Visual Basic Internet Routines
Pure VB: Obtain the Current URL from IE or Netscape
Posted:   Friday July 26, 2002
Updated:   Monday December 26, 2011
Applies to:   VB4-32, VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   None
Author:   Joe LeVasseur
IE3 or later installed.

Its interesting how many people have a need to identify the current URL from the address bar of an open IE or Netscape session.  This is by far the simplest means ... using DDE conversation.

The results of the call to IE return two items - the site's URL as displayed in the IE address bar, and the IE Browser's window title. Both are returned as a single string, individually quoted and comma-delimited.

Netscape, on the other hand, always returns three pieces of information - URL, title and frame - and the information returned differs depending on the user's action with the site. If the site was just navigated to (no interaction has occurred within a site's pages), the site URL and title are returned just as with IE (the no interaction example in the illustration), and the frame position contains an empty string. But if interaction has taken place, the DDE conversation returns the URL of the page upon which the interaction took place, that page's title, and the name of the frame in which that page is located.

Thanks go out to MVP Joe LeVasseur for providing this code to the newsgroups.

 BAS Module Code

 Form Code
Drop a command button (Command1) two labels (Label1, Label2) onto a form, setting the autosize property of the labels True. The third label in the illustration above is the result of preparing the graphic as a composite image to demonstrate both NS modes. Add the following code to the form:

Option Explicit
' Copyright 1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
Option Explicit

Private Sub Command1_Click()
   On Error GoTo command_error
   With Label1
      .Caption = ""
      .AutoSize = True
      .LinkTopic = "IExplore|WWW_GetWindowInfo"
      .LinkItem = "0xffffffff"
      .LinkMode = 2
   End With
   With Label2
      .Caption = ""
      .AutoSize = True
      .LinkTopic = "Netscape|WWW_GetWindowInfo"
      .LinkItem = "0xffffffff"
      .LinkMode = 2
   End With
   Exit Sub


   'try the next step on error
    Resume Next
End Sub
Note that when there are multiple IE or multiple Netscape browsers open, the DDE call only acts upon the last-active browser.


PayPal Link
Make payments with PayPal - it's fast, free and secure!


Copyright 1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy


Hit Counter