android - Clicking on Google ad in a WebView loads the link in the WebView itself -
i'm loading google advertisement in webview
code shown below. when click on advertisement link opens in webview
itself.
how can open in android browser?
i tried setting webviewclient
shouldoverrideurlloading
when click advertisement method not called.
when run javascript code in chrome
on pc opens correctly in new window.
what missing?
edit
i tried utilize onloadresource
observe click events listening loading of url containing googleads.g.doubleclick.net
issue such url loaded during advertisement loading, i.e. before clicking.
how can mimic behaviour of chrome, opens url in new window without hacking?
ad.html
<!doctype html> <html> <head> <script type='text/javascript'> var googletag = googletag || {}; googletag.cmd = googletag.cmd || []; (function() { var gads = document.createelement('script'); gads.async = true; gads.type = 'text/javascript'; var usessl = 'https:' == document.location.protocol; gads.src = (usessl ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; var node = document.getelementsbytagname('script')[0]; node.parentnode.insertbefore(gads, node); })(); </script> <script type='text/javascript'> googletag.cmd.push(function() { googletag.defineslot('/123456789/xxxx', [320, 50], 'div-gpt-ad-123456789-0').addservice(googletag.pubads()); googletag.pubads().enablesinglerequest(); googletag.enableservices(); }); </script> </head> <body> <div id='div-gpt-ad-123456789-0' style='width:320px; height:50px;'> <script type='text/javascript'> googletag.cmd.push(function() { googletag.display('div-gpt-ad-123456789-0'); }); </script> </div> </body> </html>
java code
webview advertisement = (webview) view.findviewbyid(r.id.ad); ad.getsettings().setjavascriptenabled(true); ad.setwebviewclient(new webviewclient() { @override public boolean shouldoverrideurlloading(webview view, string url) { // never gets here! super.shouldoverrideurlloading(view, url); homecoming false; } @override public void onloadresource(webview view, string url) { super.onloadresource(view, url); if (url.contains("googleads.g.doubleclick.net")) { startactivity(new intent(intent.action_view, uri.parse(url))); view.stoploading(); } } }); ad.loadurl("file:///android_asset/html/ad.html");
android android-webview
No comments:
Post a Comment