I use google dfp to display ads in my PhoneGap project, and these ads appear as frames.
When a user clicks on an ad, I would like the URL to be open in InAppBrowser . For now, it just opens the URL in the WebView .
The anchor tag inside the iframe has target="_blank" , but I believe because it is inside the iframe, PhoneGap ignores this.
I know that InAppBrowser works for other links that I have in my project, so I solved it.
Here are some settings in my config.xml file:
... <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="*" />
Here's what the displayed 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 currently have some jQuery that checks all anchor tags that have a _blank target and opens them in InAppBrowser , however this function does not work with the displayed iframe:
$(document).on('click', 'a[target=_blank]', function (event) { event.preventDefault(); window.open($(this).attr('href'), '_blank'); });
Any help would be appreciated.
source share