Disabling JavaScript errors in WebBrowser control in Silverlight

我与影子孤独终老i 提交于 2019-12-12 09:10:39

问题


I'm developing Silverlight OOB application and I need to show web pages in it - I would like to do it through out WebBrowser control, but during page load I get lots of MessageBoxes with JavaScript errors.

Is there a way of hiding those MessageBoxes?

In winform WebBrowser control there is ScriptErrorsSuppressed property that can be used, but in SL there isn't.

I would be appreciated for any help.


回答1:


Try turning off script debugging in the internet explorers advanced settings. Ultimately the control uses MSHTML to deliver the rendering, which in turn gets many of it settings from IE.




回答2:


Today I've returned to this problem in my app and I was able to resolve it somehow. Because I need to show only a pages - without much user interaction on those pages - I solve it this way.

In code I create a html with iframe with attribute security="restricted" and then I inject url to this iFrame.

My code looks like this:

var html = new StringBuilder(@"<html xmlns=""http://www.w3.org/1999/xhtml"" lang=""EN""> 
                                            <head> 
                                            <meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" /> 
                                            <title>{@pageTitle}</title> 
                                            <style type=""text/css""> 
                                            html {overflow: auto;} 
                                            html, body, div, iframe {margin: 0px; padding: 0px; height: 100%; border: none;} 
                                            iframe {display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden;} 
                                            </style> 
                                            </head> 
                                            <body> 
                                            <iframe id=""tree"" name=""tree"" security=""restricted"" src=""{@PageLink}"" frameborder=""0"" marginheight=""0"" marginwidth=""0"" width=""100%"" height=""100%"" scrolling=""auto""></iframe> 
                                            </body> 
                                            </html>");
html.Replace("{@pageTitle}", Title);
html.Replace("{@PageLink}", uri.ToString());

and then I'm using NavigateToString method of WebBrowser to load my html to it.

P.S. I've added this as an answer to accept this question.



来源:https://stackoverflow.com/questions/4931842/disabling-javascript-errors-in-webbrowser-control-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!