i am using VS 2005 and WebBrowser control. When i using component to navigate to specified page i get scenario error, like "On this page javascript scenario error" and two buttons: yes or no executing scenario. How to prevent alert windows and continue browsing without this messages?
i am using VS 2005 and WebBrowser control. When i using component to navigate to specified page i get scenario error, like "On this page javascript scenario error" and two buttons: yes or no executing scenario. How to prevent alert windows and continue browsing without this messages?
Share Improve this question edited Mar 29, 2011 at 15:20 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Mar 29, 2011 at 6:46 Vytas P.Vytas P. 9834 gold badges12 silver badges18 bronze badges 4- 1 Do you want to disable the script errors? or do want to disable confirm boxes? – Anuraj Commented Mar 29, 2011 at 7:19
- I want to disable confirm boxes. – Vytas P. Commented Mar 29, 2011 at 8:11
- I don't think it is possible. :( – Anuraj Commented Mar 29, 2011 at 8:39
- It's an IE's setting. You can change it by yourself in Browser Options – Genius Commented Mar 29, 2011 at 8:57
3 Answers
Reset to default 9Try
WebBrowser1.ScriptErrorsSuppressed = true;
Try this
HtmlElement head = WebBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = WebBrowser1.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
string alertBlocker = @"window.alert = function () { }; window.confirm=function () { };";
element.text = alertBlocker;
head.AppendChild(scriptEl);
WebBrowser1.ScriptErrorsSuppressed = true;
Source : http://moshez.blogspot.co.il/2013/08/c-disable-alert-box-javascript-in-c.html
Private Sub WebBrowser1_StatusTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles WebBrowser1.StatusTextChanged
On Error Resume Next
Dim head As HtmlElement = WebBrowser1.Document.GetElementsByTagName("head")(0)
Dim script As HtmlElement
script = WebBrowser1.Document.CreateElement("script")
script.SetAttribute("type", "text/javascript")
Dim alertBlocker As String = "window.alert = function () { }; window.confirm=function () { }; "
script.SetAttribute("text", alertBlocker)
head.AppendChild(script)
End Sub