user968341
user968341

Reputation: 203

access url from microsoft web browser control in mfc VC++

i am using Microsoft web browser control in an MFC Application.

It displays a login page initially using

control.navigate(URL) method

After login i need to access the URL from the control.

How this can be done?

Can anyone help me out

Upvotes: 0

Views: 1561

Answers (3)

Sheng Jiang 蒋晟
Sheng Jiang 蒋晟

Reputation: 15261

The URL is sent to you in the DocumentComplete event. Check the MFCIE sample, the sample handles the event to update its address bar.

Note the url may be different from the one you passed to Navigate or get from OnBeforeNavigate2. For example if you pass microsoft.com to Navigate2, you will get www.microsoft.com back due to server side redirects.

Upvotes: 1

Serge Wautier
Serge Wautier

Reputation: 21878

The WebBrowser control has an event OnBeforeNavigate2 that fires before switching pages. The event handler receives the new visited URL.

If you use a CDHTMLView, you don't even have to add an event handler: Just override the virtual OnBeforeNavigate2().

Upvotes: 1

icabod
icabod

Reputation: 7074

MSDN has a section all about "Using MFC to Host a WebBrowser Control". In there it mentions using the following:

//CWebBrowser2 m_browser - to access the WebBrowser control  

CString string1, string2;

string1 = m_browser.GetLocationName(); // gets the page title
string2 = m_browser.GetLocationURL();  // gets the page URL

Regarding when you try to get that information, you could check m_browser.Busy(...) or m_browser.ReadyState(...) to see if any kind of navigation/download is currently happening.

I confess to never using the control myself so don't know if there's a simple way to get a callback saying that the URL has changed, but the above link should give you most of the information you need. Hopefully :)

Upvotes: 0

Related Questions