Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with scripting when downloading html pages with the Browser Control

23 views
Skip to first unread message

Winfried Kaiser

unread,
Jun 17, 2001, 10:07:41 AM6/17/01
to
I am using the Browser control to download web pages into my program.

While this works perfectly well, I do have a problem if "Script debuging" is
enabled in IE.

I do not download the whole frame structure of the document, because most of
that I do not need.

If the page actually downloaded, however, contains a script, which
references objects in another frame, which I did not download, IE pops up a
message-window saying, that a script error has occurred and asking, if I
would like to start the script debugger.

How can I suppress this message, apart from disabling script debugging in
the IE altogether?

I tried to do a "Browser.Stop" in the "Document_Complete" event, which
supposedly should stop all active content (like animated gif's and scripts),
but this did not work.

--
Dipl.-Ing.(TH) Winfried Kaiser
Fortune Systems GmbH & Co.
Schleswiger Str. 22a, D-24975 Husby, Germany


Jan Ostedt

unread,
Jun 18, 2001, 5:02:14 AM6/18/01
to
The web browser control fires an ONERROR event when a script error
occurs. If you set up your own event handler for that event you can suppress
the script error dialog. You can find more information about how to do this
in a previous thread in this news group. Take a look at:
http://groups.google.com/groups?hl=en&lr=&safe=off&ic=1&th=a4959bcabcfda5f4,8&seekm=1e0d9to58liojdmr8hku9t2rb4ht3rkaqh%404ax.com
Regards
Jan

Winfried Kaiser

unread,
Jun 20, 2001, 1:24:58 AM6/20/01
to
Hi, Jan,

thanks for the answer.

I forgot to mention, that I was looking for a solution in VB.

The interface there, of course, is much easier (and might have helped you to
identify the parameters more easily.)

What I am doing is:

Dim WithEvents Win As HTMLWindow2

Private Sub Win_onerror(ByVal description As String, ByVal url As String,
ByVal line As Long)
Stop
End Sub

Unfortunately, this routine is not entered on a script error and the
unwanted Browser message pops up!

--
Dipl.-Ing.(TH) Winfried Kaiser
Fortune Systems GmbH & Co.
Schleswiger Str. 22a, D-24975 Husby, Germany

"Jan Ostedt" <ost...@algonet.se> schrieb im Newsbeitrag
news:bffritses5bsc5lgc...@4ax.com...

Jan Ostedt

unread,
Jun 20, 2001, 4:09:12 AM6/20/01
to
Hi again!
This is probably not what you want to hear, but the question about how to solve this problem in VB has been raised
before and so far I haven't seen any solution being posted.
http://groups.google.com/groups?q=HTMLWindow2+onerror+event+not+firing+in+VB&hl=en&safe=off&rnum=1&ic=1&selm=%238GtVpz1AHA.824%40tkmsftngp03
Regards
Jan

FWBlack

unread,
Jun 20, 2001, 9:51:19 AM6/20/01
to
You can do this in VB, however you need to use something like Edanmo's
OLELIB (http://www.domaindlx.com/e_morcillo/default.asp). Then you'll need
to implement IOleCommandTarget (among other things). You can then catch the
script error by checking hte pguidCmdGroup and then the nCmdID for
OLECMDID_SHOWSCRIPTERROR and set pvaOut=0. If IE is set to disable script
debugging (If the user of my app has selected to block script errors, I
automatically set this IE registry entry in my app so that this will always
work.) it will work - you will not get the error. I've also set the
HTMLWindow2 onError event basically as you've done, however I set it to
popup a message box - this might be required, I can't remember...

Hope this helps.
Fred


"Winfried Kaiser" <WKa...@fortune.de> wrote in message
news:#7J9MtU#AHA.2016@tkmsftngp03...

Winfried Kaiser

unread,
Jun 22, 2001, 1:18:01 AM6/22/01
to
This seems to be a "No win"-situation in VB.

Although I have managed now to invoke the "Win_onerror" event (by setting
the Windows Reference in the "Download_Complete"-Event like "Set
Win=InternetExplorer1.Document.parentWindow"), this does not help too much!

The problem is, that, if the Explorer advanced Options "Disable Script
debugging" and "Show Script errors" (or however they might be called in the
english version) are not set to "Disable Script debugging" and "Do not show
Script errors" then, either the script debugger invocation or script error
messages are displayed. And only after this message is processed by the
user, the Win_onerror-event is entered.

So, the only way to solve the problem I could figure out is, to set the a.m.
options in the registry, so that no script error message is displayed at
all.

Of course, to be polite, you should restore the original user setting after
you finish using the IE control.

What I have done is:

Private Declare Function SendMessageByString Lib "user32" Alias
"SendMessageA" _

(ByVal hWnd As Long, _

ByVal wMsg As Long, _

ByVal wParam As Long, _

ByVal lParam As String) As Long

Const ExplorerPath$ = "SOFTWARE\Microsoft\Internet Explorer\Main"


Const ScriptDebuggerKey$ = "Disable Script Debugger"

Const ShowScriptErrorKey$ = "Error Dlg Displayed On Every Error"

Const NewScriptDebuggerKey$ = "yes", NewShowScriptErrorKey$ = "no"

Dim OldScriptDebuggerKey$, OldShowScriptErrorKey$, ChangeDebuggerKey,
ChangeScriptErrorKey

On Loading the form containig the control you add the following:

If RegOpenKey(HKEY_CURRENT_USER, ExplorerPath$, hKey) Then

R& = RegQueryStringValue(hKey, ScriptDebuggerKey$,
OldScriptDebuggerKey$)

R& = RegQueryStringValue(hKey, ShowScriptErrorKey$,
OldShowScriptErrorKey$)

ChangeDebuggerKey = OldScriptDebuggerKey$ <> NewScriptDebuggerKey$

ChangeScriptErrorKey = OldShowScriptErrorKey$ <> NewShowScriptErrorKey$

If ChangeDebuggerKey Or ChangeScriptErrorKey Then

If ChangeDebuggerKey Then

R& = RegSetStringValue(hKey, ScriptDebuggerKey$,
NewScriptDebuggerKey$)

End If

If ChangeScriptErrorKey Then

R& = RegSetStringValue(hKey, ShowScriptErrorKey$,
NewShowScriptErrorKey$)

End If

End If

Call RegCloseKey(hKey)

If ChangeDebuggerKey Or ChangeScriptErrorKey Then

Call RefreshBrowserSettings(ExplorerPath$)

End If

End If

On Unloading the form containig the control you add the following:

If ChangeDebuggerKey Or ChangeScriptErrorKey Then

If RegOpenKey(HKEY_CURRENT_USER, ExplorerPath$, hkey) Then

If ChangeDebuggerKey Then

R& = RegSetStringValue(hkey, ScriptDebuggerKey$,
OldScriptDebuggerKey$)

End If

If ChangeScriptErrorKey Then

R& = RegSetStringValue(hkey, ShowScriptErrorKey$,
OldShowScriptErrorKey$)

End If

Call RegCloseKey(hkey)

Call RefreshBrowserSettings(ExplorerPath$)

End If

End If

Finally add the following routine to notify IE of changed settings:

Private Sub RefreshBrowserSettings(RegKey$)

' Broadcast that some setting changed under some registry key

On Error Resume Next


Const HWND_BROADCAST As Long = 65535

Const WM_SETTINGCHANGE As Long = 26


R& = SendMessageByString(HWND_BROADCAST, WM_SETTINGCHANGE, 0&, RegKey$)

End Sub


Alas, this still does not solve the problem completely! It works, if the
Browser UI is displayed. However, if you hide the browser control, as I do,
the bloody message is still displayed.

So, as a last resort, I am now loading this offending page via WININET and
stuff it into the browser after the download, in order to be able to access
the object model an print the page.

Very awkward behaviour, needs definitely to be corrected by MS.

0 new messages