Embedded IE browser: how to detect redirect before

2019-09-09 03:38发布

问题:

I am hosting an OAuth page in an embedded browser. I want to close the login page as soon as possible without waiting for the redirect page to load (the OAUth provider requires a valid redirect url).

How do I detect navigation to the redirect url? OnBeforeNavigate fires for one url, but OnNavigateComplete for the final url, and it (obviously) takes time to navigate and load the page. I would prefer to skip that step by detecting redirect and bailing out before the browser actually hits the final redirect page.

Thanks!

回答1:

In the host implementation of IDocHostUIHandler::GetHostInfo, turn on the DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION flag. You will then get a DWebBrowserEvents2::BeforeNavigate2 for each redirect, and can cancel a redirect if you want.