Skip to content

Instantly share code, notes, and snippets.

@heymatthenry
Created February 15, 2012 18:22
Show Gist options
  • Select an option

  • Save heymatthenry/1837975 to your computer and use it in GitHub Desktop.

Select an option

Save heymatthenry/1837975 to your computer and use it in GitHub Desktop.
Minimum test case for an iframe with a remote src pointing at an ad tag. The behavior we'd like to see is for links inside the iframe to open in the Android browser. Currently they just open inside the iframe (as you might expect). Changing the target att
<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
</head>
<body>
<iframe src="http://mwhenry.com/ad.html" />
</body>
</html>
@macdonst
Copy link

Okay, this was an interesting problem. Thanks for sending it to me as I now feel like I have an even better idea of what goes on under the hood. While one would think you could modify DroidGap.shouldOverrideUrlLoading() to get the behaviour you desire but that is not the case as it is not called for iframes. If you want to cause the Android browser to open you'll need to override a method in your Java class that extends DroidGap. Something like this:

@Override
public void onLoadResource (WebView view, String url) {
    Log.d("Toura", "onLoadResource: " + url);
    if (url.contains("toura")) {
        if(view.getHitTestResult().getType() > 0){
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
            view.stopLoading();
        }
    }
}

You'll have to decide a mechanism of when to redirect to the external browser. Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment