Click here to Skip to main content
14,690,613 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
WebBrowser web = new WebBrowser();
web.NewWindow += new CancelEventHandler(web_NewWindow);
web.Navigate(websiteURL);

while (web.ReadyState != WebBrowserReadyState.Complete)
{
   Application.DoEvents();
}


Hi, in my underlined line, it comes a message error that says:


_Internet Explorer Script Error______________
An error occurred in the script on this page.
Line: 4
Char: 10997
Error: 'null' is null or not an object
URL: (websiteURL)

Do you want to continue running scripts on this page?
____ ____
|YES | |NO|
_____________________________________

Please help me to run my:
WebBrowser web = new WebBrowser();

in Firefox... or how can I just abort this message?
Posted
Comments
Sunny_Kumar_ 18-May-12 8:14am
   
share the website URL

1 solution

Hi there,

This sin't a problem with the WebBrowser control, or even your code. It is a problem with the web page you are trying to load. The page evidently contains a JavaScript error so when this error occurs the WebBrowser control is just giving you the option to stop running the page. You have two options therefore:
1) Ignore the error and continue to show the page. This may result in some bits of the page not working but it will mean that the page shows. If you can edit the page, do so and fix the error :)
2) Handle the error by telling the user and giving the user the option or redirecting a different page.

Hope this helps,
Ed
   
Comments
Killzone DeathMan 18-May-12 9:41am
   
I want to '1)Ignore the error and continue to show the page.' in my C# code,but how?
Ed Nutting 18-May-12 9:48am
   
Try looking for a way to suppress JavaScript events (I'm sorry I cannot provide a link right now). You could try wrapping the method call in a try-catch block and then wrap all that in a loop until there are no more events to "do".

Hope this helps,
Ed
Killzone DeathMan 18-May-12 9:52am
   
I already try with the:
try
{
WebBrowser web = new WebBrowser();
web.NewWindow += new CancelEventHandler(web_NewWindow);
web.Navigate(websiteURL);

while (web.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}

}
catch(Exception ex)
{
MessageBox.Show("test");
}

it don´t display my 'test' messagebox... only display the error message...
Ed Nutting 18-May-12 9:58am
   
Oh you mean to say that the web browser control pops up the message box! This makes the problem so much clearer! I think there is a property called "ScriptErrorsSuppressed", see here:
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.scripterrorssuppressed.aspx
Set this to true and the popup will go away.

What is happening is the page is loading and the JavaScript is throwing an error. This error is an event and this event is specifically to display a message box to the user. So when you call DoEvents it causes the message box to be displayed. So to stop this happening you set "SuppressScriptErrors" and it won't show the message box.

This should solve your issue,
Ed
Killzone DeathMan 18-May-12 10:07am
   
Ahahahaha it works, it works!!! :D
Dammit your are good, you are hired!
Thanks a lot friend, I love you! :D
Better is when you give me you e-mail to help me for more things...
Ed Nutting 18-May-12 10:11am
   
Glad I could help and don't worry keep posting questions on CP, I'll keep an eye out for them :)
Ed Nutting 18-May-12 10:12am
   
Oh by the way, please don't forget to up-vote/accept solution.

Thanks,
Ed
Killzone DeathMan 18-May-12 10:13am
   
OK! Your are my boy :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900