Results 1 to 5 of 5

Thread: [RESOLVED] LocationName & LocationURL!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Resolved [RESOLVED] LocationName & LocationURL!

    In a WebBrowser project, I am keeping a tab on the history of the URLs that a user has visited by populating the title of the web pages (using the WebBrowser's LocationName property) that the user has visited each day & their corresponding URLs (using the WebBrowser's LocationURL property) in a text file. The title of the web pages & their URLs are comma-delimited. Here's how a sample text file would look:

    "Yahoo!","http://www.yahoo.com"
    "BBC","http://www.bbc.com"
    "CNN","http://www.cnn.com"
    "MSN","http://www.msn.com"

    I am populating the text file in the WebBrowser's ProgressChange event function. I could have done the same in the DocumentComplete event function as well but that would mean that a URL will get listed in the history if & only if the user has downloaded the entire web page. Often it happens that while a page is getting downloaded, users click another link. So populating the text file in the DocumentComplete event function under such circumstances won't list such a URL in the history which is why I am populating the text file in the ProgressChange event function. This is how I am populating the text file:
    VB Code:
    1. Private Sub wWeb_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    2.     Dim i As Integer
    3.     Dim iFile As Integer
    4.     Dim FileName As String
    5.  
    6.     iFile = FreeFile
    7.     FileName = App.Path & "\History.txt"
    8.     Open FileName For Output As #iFile
    9.         Write #iFile, wWeb.LocationName, wWeb.LocationURL
    10.     Close
    11. End Sub
    The problem with the above code is often I find that wWeb.LocationName & wWeb.LocationURL happen to be the same though the web page exclusively has a title. Under such circumstances, the text file looks like this:

    "http://www.yahoo.com","http://www.yahoo.com"
    "http://www.bbc.com","http://www.bbc.com"
    "http://www.cnn.com","http://www.cnn.com"
    "http://www.msn.com","http://www.msn.com"

    So when the History is viewed, users see the URL of the web pages & not the title of the web pages (which definitely makes it harder for users to jump from one page to another).

    Now how do I ensure that wWeb.LocationName always returns the title of web pages & not the URL?

    I tried populating the text file in the WebBrowser's DownloadBegin, StatusTextChange & TitleChange event functions but that doesn't resolve the issue.

    One way of retrieving the title is from the HTML source code of the web page using
    VB Code:
    1. Text1.Text = wWeb.Document.DocumentElement.InnerHTML
    & then searching for <title>....</title> but I would like to avoid this approach.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  2. #2
    Member
    Join Date
    Feb 2006
    Posts
    50

    Re: LocationName & LocationURL!

    VB Code:
    1. Write #iFile, wWeb.LocationName & "," & wWeb.LocationURL

  3. #3

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: LocationName & LocationURL!

    I guess you haven't understood what I am looking out for. The suggestion you have given is something which I already know. The problem doesn't lie there. The problem is often the title of the web page happens to be the same as the URL of the web page (have a look at the contents of the 2 text files I have shown in post #1). In other words, wWeb.LocationName doesn't give the title of the web page. This is what I don't want.


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

  4. #4
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: LocationName & LocationURL!

    Arpan, try using the DOM to extract the title :
    VB Code:
    1. wWeb.Document.title
    or, if that doesn't work:
    VB Code:
    1. wWeb.Document.getElementsByTagName("title").item(0)
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  5. #5

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Re: LocationName & LocationURL!

    TheVader, you have given me a gem of an idea! Your first suggestion did wonders for me; so didn't bother to try out the second one

    Actually I have been dwelling on this niggling issue for quite some time but thanks to you, with your help I got it resolved once & for all (I hope so!). Good riddance to bad rubbish


    ARPAN

    IF YOU HAVE AN APPLE & I HAVE AN APPLE AND WE EXCHANGE THE APPLES, THEN YOU & I WILL STILL HAVE ONE APPLE BUT IF YOU HAVE AN IDEA & I HAVE AN IDEA AND WE EXCHANGE OUR IDEAS, THEN EACH OF US WILL HAVE TWO IDEAS!

    NOTHING IS IMPOSSIBLE IN THIS WORLD.....EVEN THE WORD IMPOSSIBLE SAYS I'M POSSIBLE!

    PRACTICE MAKES A MAN PERFECT BUT NOBODY IS PERFECT; SO WHY PRACTICE?

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