Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Phonegap - Open iframe links in external browser instead of Phonegap WebView
    primarykey
    data
    text
    <p>I'm having what seems to be a pretty small issue in the <strong>Phonegap 1.3.0</strong> application I am working on. It is for Android devices.</p> <p>The problem is stemming from the ads I am trying to incorporate into my app. I am trying t use Leadbolt's no-SDK offer wall as well as their banner ads.</p> <p>I am loading the offer wall within an iframe in my app, inside of a hidden DIV, and then displaying it when required - this part is working great.</p> <p>The problem comes when I click on one of the links on the offer wall: instead of launching the clicked URL in a new External/Native browser, the link is being opened within the iframe. The same thing happens when someone clicks the banners, though these are integrated by inserting a in the location you want the ad to show rather than via an iframe. (Maybe the script injects an iframe, dunno, the end behavior is the same)</p> <p>What I'm trying to do now is to implement a method in Java to catch any clicks, and open a new browser if the link is not relative/local - i.e. if it is prefixed by "http", "https", or "market" protocols</p> <p>And here lies the real issue - the only experience I have with Java has been messing with Phoengap a bit :(</p> <p>I have been reading and testing things all day, but finally I must resort to asking those of you who are more knowledgeable than I am in regards to Java programming.</p> <p>Here is what I have been attempting so far:</p> <pre><code>package com.phonegap.my_great_app; import android.os.Bundle; import android.webkit.WebView; import com.phonegap.*; public class MyGreatApp extends DroidGap { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.loadUrl("file:///android_asset/www/index.html"); /* Intercept clicked links, and open external URLs in external browser */ public boolean shouldOverrideUrlLoading(DroidGap super, String url) { if (url != null &amp;&amp; url.startsWith("market://") || url.startsWith("http://") || url.startsWith("https://")) { /* Open new WebView or external browser with URL */ /* Do it here */ Uri uri = Uri.parse(url); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } else { /* Do nothing, it's relative URL from my app */ return false; } } } } </code></pre> <p>I am sure this code is laughably wrong, but hopefully it can illustrate what I'm trying to achieve here. Truth be told, I have no idea if shouldOverrideUrlLoading() is even the right method to be calling for this problem!</p> <p>I will be very grateful for any advice or code samples you can offer! Thanks :)</p> <p><strong>EDIT: Just to be clear - I cannot alter the iframe source code so javascript or changing the link targets is not an option due to XSS issues.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload