Go Back  Xtreme Visual Basic Talk > Other Languages > Web Programming > Javascript Interact With VB Progg


Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2004, 08:05 PM
acer2k acer2k is offline
Newcomer
 
Join Date: Jan 2004
Posts: 4
Arrow Javascript Interact With VB Progg

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)
Reply With Quote
  #2  
Old 01-05-2004, 07:36 AM
dionyziz dionyziz is offline
Centurion
 
Join Date: Sep 2003
Location: Ioannina, Greece
Posts: 146
Default

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)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript in Webbrowser control through VB... jeremyrharris General 4 09-14-2003 03:25 PM
VB interact with other aplications? VBDude General 1 04-08-2003 12:50 PM
QB to VB Conversion - By AIO BillSoo Tutors' Corner 0 08-06-2002 11:37 AM
why not use flash? wild wolf Game Programming 24 01-29-2002 11:04 AM
Any function in VB works like eval() in javascript Ming General 2 08-06-2001 05:31 AM

Advertisement:

Powered by liquidweb