Go Back   Forum Care Forums > Development Reference Area > Visual Basic

Reply
 
LinkBack Thread Tools Display Modes
Javascript & WebBrowser1 control
Old
  (#1)
Florin
Guest
 
Posts: n/a
Default Javascript & WebBrowser1 control - 06-04-2007, 09:47 AM

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
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: Javascript & WebBrowser1 control
Old
  (#2)
Hal Rosser
Guest
 
Posts: n/a
Default Re: Javascript & WebBrowser1 control - 06-04-2007, 09:47 AM

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" <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED 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


   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: Javascript & WebBrowser1 control
Old
  (#3)
mayayana
Guest
 
Posts: n/a
Default Re: Javascript & WebBrowser1 control - 06-04-2007, 09:47 AM


I didn't test your dynamic writing of the script tag,
but I'll ***ume 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 <EMAIL REMOVED> wrote in message
news:EMAIL REMOVED 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



   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top