471,108 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Javascript & WebBrowser1 control

Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click()
WebBrowser1.Navigate "javascript:callAlert()"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)

Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"");" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " //-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Document.body.innerHTML = sHTML

End Sub
Jul 17 '05 #1
2 7656
put an html button on the page with an onClick event handler that calls the
javascript function
server-side script can't call client-side script functions

"Florin" <fl*****@mccowan.ca> wrote in message
news:29**************************@posting.google.c om...
Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click()
WebBrowser1.Navigate "javascript:callAlert()"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"");" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " //-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Document.body.innerHTML = sHTML

End Sub

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Jul 17 '05 #2

I didn't test your dynamic writing of the script tag,
but I'll assume that part works.
If you reference MSHTML.TLB in the project you
get access to the DOM.
I'm not sure what syntax you'll need to get access
to the script. Maybe something like this will work:

Dim Doc As mshtml.HTMLDocument
Set Doc = WebBrowser1.Document
s = Doc.scripts.Item("callAlert()")
Doc.parentWindow. execScript("callAlert()", "javascript")

--
--
Florin <fl*****@mccowan.ca> wrote in message
news:29**************************@posting.google.c om...
Hi,

How can get the javascript using a button Command1 ?
I want to create the html on the fly.
This one doesn't work:

Private Sub Command1_Click()
WebBrowser1.Navigate "javascript:callAlert()"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim sHTML As String
sHTML = "<P>This is some text.</P>"

sHTML = sHTML & "<script type=""text/javascript"">" & vbCrLf
sHTML = sHTML & "<!--" & vbCrLf
sHTML = sHTML & "function callAlert(){" & vbCrLf
sHTML = sHTML & "alert(""Test"");" & vbCrLf
sHTML = sHTML & "}" & vbCrLf
sHTML = sHTML & " file://-->" & vbCrLf
sHTML = sHTML & "</script>" & vbCrLf

WebBrowser1.Document.body.innerHTML = sHTML

End Sub

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Trevor Fairchild | last post: by
reply views Thread by Juan Jose Costello Levien | last post: by
2 posts views Thread by FatBo | last post: by
16 posts views Thread by nime | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.