LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

capturing main frame URL from WebBrowser object

Solved!
Go to solution

I have registered a callback VI to handle the DocumentComplete event from a WebBrowser object.  I pass a string reference as the user param to the callback VI, and I update the string with the URL each time the DocumentComplete event fires.

 

On a page with multiple frames, the DocumentComplete event fires multiple times, and I often end up with a URL pointing to an advertisement.  Is there a way to determine whether the DocumentComplete came from the main frame?  On non-LabVIEW forums, I see discussions of performing comparisons using pDisp to determine which DocumentComplete call corresponded to the main frame.

 

Has anyone else encountered this problem using the WebBrowser object in LabVIEW and solved the problem?

0 Kudos
Message 1 of 8
(4,140 Views)

Hello,

 

Do you have an example VI coded that demonstrates the error you are seeing? 

 

Thanks, 

Patrick Corcoran
Application Engineering Specialist | Control
National Instruments

0 Kudos
Message 2 of 8
(4,115 Views)

I used this LabVIEW example as my starting point:
http://zone.ni.com/devzone/cda/epd/p/id/2743

 

I attached a LLB with my modification to gethtmlsourcestring.vi that adds the callback.  With this chage, you can navigate around and the URL will change.

 

When I go to a site such as
http://news.google.com/nwshp?hl=en&tab=wn
the final URL ends up at
http://fastflip.googlelabs.com/embed?source=news&browse=2&fullw=300
instead of staying at http://news.google.com/nwshp?hl=en&tab=wn as seen in a normal browser.  This would make the ability to bookmark or refresh the news page impossible.

 

On a page with many frames of advertisement, the documentcomplete callback fires many times and the final URL is wrong.

 

The technique Microsoft recommends at http://support.microsoft.com/kb/180366 is in this excerpt:

 

"The top-level frame fires the DocumentComplete in the end. So, to check if a page is done downloading, you need to check if the IDispatch* parameter is same as the IDispatch of the WebBrowser control."

If I can create a DocumentComplete callback that catches this condition, then I can create a proper address bar with the correct URL.

 

Please investigate and let me know if there is a LabVIEW way to do this.  Thanks!

 

0 Kudos
Message 3 of 8
(4,105 Views)

I don't know if this is the same as the Microsoft technique but it seems to work. Just ignore the Event Data cluster in your callback. Instead simply wire a property node to the Control Ref and select the LocationURL property. Wire that to the Value property of your URL string reference.

=====================
LabVIEW 2012


0 Kudos
Message 4 of 8
(4,090 Views)
Solution
Accepted by topic author clnorris

 

Here is a screenshot of what I was describing above. Let me know if this solved it for you.

 

callback to capture URL.png

=====================
LabVIEW 2012


0 Kudos
Message 5 of 8
(4,056 Views)

Hi Steve,

 

I am using your suggested modification, and this change is working well so far.  I will be testing extensively this week, and if that goes well then we can consider this solved.

 

Thanks!

 

0 Kudos
Message 6 of 8
(4,028 Views)

Obviously the callback will still fire multiple times and your referenced control will be updated each time. If this is a problem or if you need to do something when the page is loaded then you could compare the URL from the Event Data cluster with that of the CtrlRef LocationURL property. You could wire the comparison to a case structure and the code inside should execute only once. I think this is the LabVIEW equivalent to the comparison you mentioned.

 

Capture.PNG

=====================
LabVIEW 2012


0 Kudos
Message 7 of 8
(4,017 Views)

Steve,

 

Using LocationURL did the trick.  My address bar is operating flawlessly!  Thanks for taking the time to respond to my inquiry.

 

Cheers!

 

Chris Norris

0 Kudos
Message 8 of 8
(3,966 Views)