Quote:
Originally Posted by acer2k
I have a vb project that has a webbrowser control in it. Is it possible to have javascript on the webpage loaded in the webbrowser, interact with my program? (VB6)
Yes, it is possible to use the webBrowser to interact with the program(and visa versa). To send some information from the webBrowser to the program you can use many ways. The easier is to navigate to an unexisting URL which would contain the information you want to send from the WebBrowser to the program with a specific suffix in the URL. Then, using the event BeforeNavigate2 you can get the information from the URL and cancel the navigation. To be more specific, to send information to the program you can using the suffix acer2k: or whatever you like, like this:
HTML Code:
<a href="acer2k:Hello World">Click here</a> to send the information.
Then in your program:
Code:
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
If Left(URL, 7) = "acer2k:" Then
MsgBox Right(URL, Len(URL) - 7)
Cancel = True
End If
End Sub
This code will be execute just before navigating to the non-existing URL "acer2k:Hello World", parse the URL, get the necessary information and cancel the navigation. But, this still enables you to browse to
http:// or
ftp:// documents as you use the prefix "acer2k:" for any locations containing information for your program.
(Ofcourse, there's a more "professional" way to do it which is using HTML DOM objects, and it can be used either to transfer information from the WebBrowser to the program, but also to transfer data from the program to the WebBrowser control. But, it's not necessary to use it for little data)