Results 1 to 2 of 2

Thread: Use JavaScript Replace function in the WebBrowser

Hybrid View

  1. #1
    Member
    Join Date
    Aug 11
    Posts
    50

    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 08
    Posts
    6,747

    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>
    The better the information you give to begin with and the sooner you reply the sooner you will get help and get your problem resolved


    When I was young and in my prime I used to program all the time but now I'm old and getting gray I only program once a day

Posting Permissions

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