-
Mar 4th, 2006, 10:04 AM
#1
Thread Starter
Frenzied Member
[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:
Private Sub wWeb_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
Dim i As Integer
Dim iFile As Integer
Dim FileName As String
iFile = FreeFile
FileName = App.Path & "\History.txt"
Open FileName For Output As #iFile
Write #iFile, wWeb.LocationName, wWeb.LocationURL
Close
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:
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?
-
Mar 4th, 2006, 10:07 AM
#2
Member
Re: LocationName & LocationURL!
VB Code:
Write #iFile, wWeb.LocationName & "," & wWeb.LocationURL
-
Mar 4th, 2006, 10:47 AM
#3
Thread Starter
Frenzied Member
-
Mar 4th, 2006, 11:11 AM
#4
Fanatic Member
Re: LocationName & LocationURL!
Arpan, try using the DOM to extract the title :
or, if that doesn't work:
VB Code:
wWeb.Document.getElementsByTagName("title").item(0)
Author for Visual Basic Web Magazine
-
Mar 4th, 2006, 02:52 PM
#5
Thread Starter
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|