开发者

How to suppress Javascript errors thrown in WebBrowserControl Print method.

开发者 https://www.devze.com 2023-03-27 04:55 出处:网络
I have a windows c# application that uses WebBrowser Control to navigate to a webpage. I use WebBrow开发者_C百科ser.Print() to silent print this web page. Now i get some Java Script errors while print

I have a windows c# application that uses WebBrowser Control to navigate to a webpage. I use WebBrow开发者_C百科ser.Print() to silent print this web page. Now i get some Java Script errors while printing. Is it possible to suppress these. webBrowser1.ScriptErrorsSuppressed = true; doesnt seem to work as these errors occur only when printing the webpage.

Thanks, Rajee


I don't know about c# actually, but generally speaking web browsers report errors into the console only when the error event has bubbled up the DOM all the way up to the window while not being handled on its way up. If you bind a Javascript handler to "error" and prevent its further propagation, it then won't reach the document-bound default handler and supress all further errors from being reported into the console.

This is the simplest Javascript example:

window.onerror = function(){
    // Returning true informs the browser,
    // that the error has been taken care of
    return true;
}


You can try a try catch on the method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号