10-28-2010 01:16 AM
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?
Solved! Go to Solution.
10-29-2010 02:30 PM
Hello,
Do you have an example VI coded that demonstrates the error you are seeing?
Thanks,
Patrick Corcoran
Application Engineering Specialist | Control
National Instruments
10-29-2010 06:15 PM
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!
10-30-2010 04:01 PM
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.
10-30-2010 07:50 PM
Here is a screenshot of what I was describing above. Let me know if this solved it for you.
11-01-2010 11:47 AM
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!
11-01-2010 06:14 PM
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.
11-05-2010 12:10 AM
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