I have a WebView with an iframe inside. The contents of the iframe do a redirect to another URL that doesn't allow embedding in an iframe. Not a problem, actually, I just want to start the external browser activity in this case instead. The problem is that I can't find a way to intercept the redirection. None of shouldOverrideUrlLoading(), onPageStarted() or onLoadResource() get called for the redirect, hence I get no chance to start the activity.
2 Answers
In the html change the iframe tag to call some javascript function when a redirect happens
example: iFrame src change event detection?
-
1You'd have the javascript call something you added with
addJavascriptInterface
– JeffSCommented Feb 20, 2013 at 22:22 -
Sorry if I wasn't clear enough but mentioning shouldOverrideUrlLoading() and its siblings should have indicated that I'd need this functionality in Java code, not inside the browser in the iframe.– GáborCommented Feb 22, 2013 at 21:33
-
This second comment seems interesting. Thanks, I'll report back.– GáborCommented Feb 24, 2013 at 12:45
For anyone else with this problem, we found an even more simple solution to this than calling a javascript function. Simply add "target= _top" to the iframe redirect (see http://www.w3schools.com/tags/att_a_target.asp). Then shouldOverrideUrlLoading() will be called in the Android code.
-
4What? You can't set a
target
on a redirect. Your link is to information ona
elements, which are rather different from redirects. I'm not familiar with the tags on this question, so I'm not certain this is about HTTP at all, but I strongly suspect this is wrong. Commented May 14, 2014 at 17:33