6

I have created a mobile app using jQuery Mobile and built it for iOS and Android via PhoneGap Build v2.5. I then successfully added inmobi advertisements using their javascript api. The ad displays just fine but the problem comes when a user clicks the ad as the ad takes over the app. This isn't such an issue in Android as users have a back button but on iOS devices the user is stuck and unable to get back to my app.

I have successfully set up all external links contained in my app to open in the device's browser by passing all url's to this function:

function openNewBrowser(url) {
    window.open(encodeURI(url), '_system');
    return false;
}

But the inmobi ad is inside of an iframe in my app and I have no control over how they pass their url's. I have also tried to bind jQuery Mobile to catch all pagebeforechange events and process them accordingly using:

$(document).bind("pagebeforechange", function(e, data) {
    if(typeof data.toPage === 'object' || 
        data.toPage.indexOf("index.html#") >= 0) {
        //internal URL so do nothing
    } else {
        //external URL so send to openNewBrowser
        console.log('page is external');
        openNewBrowser(data.toPage);
        e.stopPropagation();
        return false;
    }
});

but the "else" is never tripped. The inmobi ad just takes over the app and user is forced to kill and restart the app back to a usable state. Is there a different event I should be listening for?

Here is how I am calling the inmobi ad:

var inmobi_conf = {
    siteid : "*******mySiteId*******",
    slot : "15",
    manual: true,
    test: true,
    targetWindow: "_blank"
};

I would (and have tried to) set the "targetWindow" to _system but the only valid parameters are "_blank" and "_top".

Does anyone know of a way to get iFrame links (that you cant set to _system) to open in the native browser instead of taking over the app or gotten inmobi ad's to not take over the app?

Jaak Kütt
  • 2,566
  • 4
  • 31
  • 39
Dom
  • 2,569
  • 1
  • 18
  • 28
  • Edit: cleaned up question to better reflect using InMobi, not adMob. – Dom May 11 '13 at 18:58
  • I ended up working around this issue by setting in the config.xml. This is a terrible work-around but its the best I have. Hopefully someone else can come up with something better. – Dom May 12 '13 at 02:03
  • Hi did you find a better solution ? – Louis Nov 02 '13 at 13:35
  • I have not. I pretty much gave up on this and am waiting for Phonegap Build to host an AdMob plugin. Hoping it will be soon. – Dom Nov 04 '13 at 11:55
  • Its not a direct answer to your question, but I gave up trying to use 3rd party ad systems. Instead I signed up to cj.com and selected the ads I wanted. Them I've built some js that loads the ads into my app and then switches the visible ad every X seconds. Let me know of you want it. You just need to know the URL of the ad and the link to use. So it can be used for any ads or any content really. – Phill Healey Apr 21 '14 at 20:18

1 Answers1

0

I ended up working around this issue by setting in the config.xml. This is a terrible work-around but its the best I have. Hopefully someone else can come up with something better.

Using a dummy iframe as the target would also work:

/*
document.body.insertAdjacentHTML
  ("beforeend", 
    "<iframe id='myframe' width='0' height='0'></iframe>"
  )
*/

document.body.appendChild
  (
  document.createElement("iframe")
  ).setAttribute("id", "myframe")

var inmobi_conf = {
    siteid : "*******mySiteId*******",
    slot : "15",
    manual: true,
    test: true,
    targetWindow: "myframe"
};

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265