Search code examples
mobileextjssencha-touch

Opening DFP Advertisements in browser window


I am able to get Google DFP ads to display in my Sencha Touch app, but when I click on these advertisements the link opens up inside of the app, making the app unusable because it is now a webpage. Is there anyway I can force the app to use the browser or an in app browser? Google DFP uses Iframes, which I am assuming can complicate things.

Thank you.


Solution

  • I was able to solve this problem using a script like this, It alters the hrefs inside of the iframe to point to the goto function, which opens the url with the InAppBrowser. But the inappbrowser must first be added to the project, which I describe below.

    function goto(url){
        var ref = window.open(url, '_blank', 'location=yes');
    }
    
    window.onload = function() {
        var link = window.frames['iframeName'].document.getElementsByTagName('a');
    
        for(i=0;i<link.length;i++) {
            link[i].href="javascript:window.top.goto('"+link[i].href+"');";
        }
    }
    

    I also had to follow the simple directions in the Accessing the Feature, section of the InAppBrowser documentation, located here: https://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html