Results 1 to 2 of 2

Thread: Use JavaScript Replace function in the WebBrowser

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    57

    Question Use JavaScript Replace function in the WebBrowser

    Hi,
    Is there any way for use JavaScript Replace function in the WebBrowser then we get the result?!
    I do not want to use Visual Basic Repalce function for some reasons

    Sorry I can not write well

    Thanks

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Use JavaScript Replace function in the WebBrowser

    Paste below code in your VB project. Put a Webbrowser control and two Command buttons on the Form. Run the project and then click button 1 to load the HTM page then click button 2 to see the results. Clicking the button on the Web doc won't do anything to get results; you need to click button2 on your VB Form.
    Code:
    Private Sub Command1_Click()
     WebBrowser1.Navigate App.Path & "\JavaScript.html"
    End Sub
    Private Sub Command2_Click()
     Results = WebBrowser1.Document.All("a4").Value
     MsgBox Results
    End Sub
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     If URL = App.Path & "\JavaScript.html" Then
       WebBrowser1.Document.All("a1").Value = "JMSRICKLAND WAS HERE"
       WebBrowser1.Document.All("a2").Value = "WAS"
       WebBrowser1.Document.All("a3").Value = "IS"
       WebBrowser1.Document.All("myButton").Click
     End If
    End Sub
    Here is the HTML document
    Code:
    <HTML>
    <BODY>
    <CENTER>
    
    <FORM NAME="myForm">
    <INPUT TYPE=Text NAME=a1 VALUE="">  
    <INPUT TYPE=Text NAME=a2 VALUE="">
    <INPUT TYPE=Text NAME=a3 VALUE="">
    
    <INPUT TYPE=hidden NAME=a4 VALUE="">
      
    <INPUT TYPE="button" NAME="myButton" VALUE="Click Me" onClick="Replace(form.a1.value, form.a2.value, form.a3.value)">
    </CENTER>
    
    <SCRIPT type="text/javascript">
    {
    function Replace(Arg1, Arg2, Arg3)
    {
      myForm.a4.value = Arg1.replace(Arg2, Arg3);
    }
    </SCRIPT>
    </FORM>
    
    </BODY>
    </HTML>


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width