axWebBrower with on-the-fly content and a JavaScript onclick funti

axWebBrower with on-the-fly content and a JavaScript onclick funti

Post by bWFsY29sbU » Thu, 04 Nov 2004 08:37:03

How do I get a web-browser loaded with on-the-fly content and a JavaScript
onclick popup function to work?

I've embedded an axWebBrowser in my (vb.net) application. The browser
starts with about:blank, and then I set AxWebBrowser1.Document.Body.innerHTML
to the desired HTML. The HTML contains a link (which works fine) and a
Javascript command to put up a popup window. (The popup will show more
on-the-fly content.)

The HTML and popup works great when I put it into a file, but I get a "A
Runtime Error has occured. Do you wish to Debug? Line 9, Error: Object
required." The HTML works fine if it's put into a file first, and then I
load it into the embedded browser as a file URL. Starting with the
about:blank and and the javascript onclick seem to be the problem.

I've reduced the code to just a single empty function.. it seems to be a
problem with the onclick that gets confused because I've started with a blank
URL.

Sample code is below. The form has one web browser, one button (to load the
content into the browser), one text box for the created HTML, and one text
box to show the browser tatus.

How do I load content into an embedded browser (on the fly) , so I can load
new content into a popup window (not a URL)? Any ideas?

-- Malcolm

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate2("about:blank")
End Sub

Public Sub loadwebcontent()
Dim myPopupCode As String
myPopupCode = "<script language=""javascript""
type=""text/javascript"">" & vbNewLine & _
"function popup() { }" & vbNewLine & "</script>" & vbNewLine

' href="#" doesn't work either..
Dim content As String = "<a href="""" onclick=""popup(); return
false;"">popup me</a>" & vbNewLine
content = content & "<p><a href="" http://www.yqcomputer.com/ "">google
me</a>" & vbNewLine
Dim myHTML As String = "<html>" & vbNewLine & _
"<head>" & vbNewLine & _
" <title> Popup Listing</title>" & vbNewLine & _
myPopupCode & vbNewLine & _
"</head>" & vbNewLine & _
"<body>" & vbNewLine & _
content & vbNewLine & _
"</body>" & vbNewLine & _
"</html>" & vbNewLine

TextBox2.Text = myHTML

' Found this jewel at
http://www.yqcomputer.com/
AxWebBrowser1.Document.Body.innerHTML = myHTML

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
loadwebcontent()
End Sub

Private Sub AxWebBrowser1_Enter(ByVal sender As System.Object, ByVal e
As AxSHDocVw.DWebBrowserEvents2_StatusTextChangeEvent) Handles
AxWebBrowser1.StatusTextChange
TextBox1.Text = e.text
End Sub
End Class