android - PhoneGap: How to make links from iframes open in InAppBrowser -


i using google dfp serve ads in phonegap project , these ads rendered iframes.

when user clicks ad, url open in inappbrowser. of now, opens url in webview.

the anchor tag within iframe has target="_blank", believe because it's within iframe, phonegap ignores this.

i know inappbrowser working other links have within project, have ruled out.

here settings in config.xml:

...  <feature name="inappbrowser">     <param name="ios-package" value="cdvinappbrowser" /> </feature> <feature name="inappbrowser">     <param name="android-package" value="org.apache.cordova.inappbrowser" /> </feature>  ...  <preference name="stay-in-webview" value="false" />  ...  <access origin="*" /> 

this rendered iframe looks like:

<div class="adunit display-block" data-adunit="example_app_section_front_footer" data-dimensions="320x50" id="example_app_section_front_footer-auto-gen-id-1">     <div id="google_ads_iframe_/2444258/example_app_section_front_footer_0__container__" style="border: 0pt none;">         <iframe id="google_ads_iframe_/2444258/example_app_section_front_footer_0" name="google_ads_iframe_/2444258/example_app_section_front_footer_0" width="320" height="50" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" src="someurl"  style="border: 0px; vertical-align: bottom;">             <html>                 <body>                     <div id="google_image_div">                         <a id="aw0" target="_blank" href="http://googleads.g.doubleclick.net/aclk?someurl" onfocus="ss('aw0')" onmousedown="st('aw0')" onmouseover="ss('aw0')" onclick="ha('aw0')"><img src="http://pagead2.googlesyndication.com/simgad/000111222" border="0" width="320" height="50" alt="" class="img_ad"></a>                     </div>                 </body>             </html>                 </iframe>     </div> </div> 

i have jquery checks anchor tags have target of _blank , opens them in inappbrowser, function doesn't work rendered iframe:

$(document).on('click', 'a[target=_blank]', function (event) {     event.preventdefault();     window.open($(this).attr('href'), '_blank'); }); 

any appreciated.

as regular links , not cordova_exec calls, need subclass cdvviewcontroller , implement webview:shouldstartloadwithrequest:navigationtype suggested above.

make sure call super in implementation.


to subclass cdvviewcontroller you'll have write native code.

at least like:

// mygapviewcontroller.h  @interface mygapviewcontroller : cdvviewcontroller  @end    // mygapviewcontroller.h  @implementation mygapviewcontroller  - (bool)webview:(uiwebview*)webview shouldstartloadwithrequest:(nsurlrequest*)request  navigationtype:(uiwebviewnavigationtype)navigationtype {     // check if super says should load     bool shouldload = [super webview:webview           shouldstartloadwithrequest:request                       navigationtype:navigationtype];      // if super says no, no need continue     if (!shouldload)     {         return no;     }      // else check here if 1 of our iframe links , it...     if (iframe)     {         //...         return no; // handled no need load iframe link in original web view     }      // else load here     return yes; }  @end 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -