Javascript & WebBrowser1 control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Florin

    #1

    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.Nav igate "javascript:cal lAlert()"
    End Sub

    Private Sub WebBrowser1_Doc umentComplete(B yVal 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.Doc ument.body.inne rHTML = sHTML

    End Sub
  • Hal Rosser

    #2
    Re: Javascript &amp; WebBrowser1 control

    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" <florinp@mccowa n.ca> wrote in message
    news:29264388.0 408201834.2cbf3 09f@posting.goo gle.com...[color=blue]
    > 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.Nav igate "javascript:cal lAlert()"
    > End Sub
    >
    > Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As[/color]
    Variant)[color=blue]
    >
    > 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.Doc ument.body.inne rHTML = sHTML
    >
    > End Sub[/color]


    ---
    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


    Comment

    • mayayana

      #3
      Re: Javascript &amp; WebBrowser1 control


      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.HTMLDocu ment
      Set Doc = WebBrowser1.Doc ument
      s = Doc.scripts.Ite m("callAlert()" )
      Doc.parentWindo w. execScript("cal lAlert()", "javascript ")

      --
      --
      Florin <florinp@mccowa n.ca> wrote in message
      news:29264388.0 408201834.2cbf3 09f@posting.goo gle.com...[color=blue]
      > 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.Nav igate "javascript:cal lAlert()"
      > End Sub
      >
      > Private Sub WebBrowser1_Doc umentComplete(B yVal pDisp As Object, URL As[/color]
      Variant)[color=blue]
      >
      > 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.Doc ument.body.inne rHTML = sHTML
      >
      > End Sub[/color]


      Comment

      Working...