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.
Asked
Active
Viewed 3.1k times
2 Answers
3
In the html change the iframe tag to call some javascript function when a redirect happens
example: iFrame src change event detection?

Community
- 1
- 1

Ben Roby G
- 118
- 9
-
1You'd have the javascript call something you added with `addJavascriptInterface` – JeffS Feb 20 '13 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ábor Feb 22 '13 at 21:33
-
This second comment seems interesting. Thanks, I'll report back. – Gábor Feb 24 '13 at 12:45
0
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.

Myles Bennett
- 533
- 4
- 12
-
4What? You can't set a `target` on a redirect. Your link is to information on `a` 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. – Brilliand May 14 '14 at 17:33