views:

128

answers:

2

Hi,
I'm using a TWebBrowser in my Delphi app. When an Internet Explorer Script Error dialog pops up it blocks automated refreshes ("the requested resource is in use"). Is there a way to automagically close the error dialog?
TIA
Steven

edit
One possible solution is to use the Mozilla ActiveX Control instead of IE's (Firefox never shows the error), but this has its own problems.

+1  A: 

You could close the dialog by clicking its button in code but probably a better way is to prevent the error that causes the dialog to display in the first place.

I'm only guessing here but I think you can get this error when you're trying to refresh the page before it's finished loading. The Navigate2 method is asynchronous, ie. it returns immediately and the browser continues loading the page in a background thread. When the document is loaded the browser triggers the OnDocumentComplete event - which you should handle to update your state variable. Don't try to call Navigate2, Refresh or Refresh2 before the current document has been loaded completely.

TOndrej
Thanks, I'll try the `Navigate2`. I'll have to wait and see if this solves it, as I don't always get the error in the first place.
stevenvh
Doeas that mean you didn't use Navigate2 to load the document? What did you use?
TOndrej
I used `Navigate`.
stevenvh
I found a site where I get the error message each and every time (http://math.stackexchange.com). I get the error also with `Navigate2`. `OnDocumentComplete` isn't triggered until I close the error dialog.
stevenvh
+4  A: 

Set the TWebBrowser Silent property to True in the Object Inspector or in code:

  WebBrowser1.Silent := True;
  WebBrowser1.Navigate2(sURl);

It will prevent the error dialog to pop up, so you don't have to close it ;-)

François
Fixed! Thanks a million!
stevenvh