Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Open Ads in new Window

I've added google adsense to my app in a webview, However i want the clicked link to open in a browser not in the very small webview

var adview = Titanium.UI.createWebView({backgroundColor:'black',width:320,bottom:0,height:50,url:'ad.html'});
win2.add(adview);
— asked June 22nd 2010 by Ryan Tregea
  • adsense
  • advertising
  • android
  • google
  • webview
0 Comments

5 Answers

  • it looks like it's not possible :

    http://developer.appcelerator.com/question/23541/possible-to-open-all-webview-links-in-new-window

    — answered June 22nd 2010 by Stephane Pelamourgues
    permalink
    0 Comments
  • Looks like Google is too clever for me, I reckon i'm on the right path though.

    Basically i looped every 400ms to check if the location has changed inside the iframe. What is happening is google automatically loads any clicked links into the top frame, So if you iframe it, It escapes and takes over the webview. Stopping my detection script.
    I think i'll check into watching it at the appcelerator level. There has to be a way to make the links open fullscreen.

    Code of Ad.html

    <html><body leftmargin="0" bottommargin="0" marginheight="0" marginwidth="0"><iframe name="fred" marginheight="0" marginwidth="0" frameborder="0" src="Ad2.html" width="100%" height="100%">
      <p>Your browser does not support iframes.</p>
    </iframe>
    <script type="text/javascript">
    function watchFrame(){
    if (fred.location.href!="file:///android_asset/Resources/Ad2.html"){
    Ti.App.fireEvent('adclick', {href:fred.location.href});
    }else{
        setInterval("watchFrame();", 400)
    }
    }
    setInterval("watchFrame();", 400)
    </script>Shouldn't See this
    </body></html>
    

    Code of Ad2.html

    <html><body leftmargin="0" bottommargin="0" marginheight="0" marginwidth="0"><script type="text/javascript"><!--
    window.googleAfmcRequest = {
      client: 'ca-mb-pub-Testing',
      ad_type: 'text_image',
      output: 'html',
      channel: 'Whatever',
      format: '320x50_mb',
      oe: 'utf8',
      color_border: '336699',
      color_bg: 'FFFFFF',
      color_link: '0000FF',
      color_text: '000000',
      color_url: '008000',
    };
    //--></script>
    <script type="text/javascript" 
       src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script></body></html>
    

    Section of App.js

     var adview = Titanium.UI.createWebView({backgroundColor:'white',width:320,bottom:0,height:50,url:'ad.html'});
           win2.add(adview);
    
    Ti.App.addEventListener('adclick', function(e) 
    { 
        Ti.API.info(e.href);
    
    });
    
    — answered June 22nd 2010 by Ryan Tregea
    permalink
    0 Comments
  • Ok, Finally Found something that will lead me in the right path.

     var adview = Titanium.UI.createWebView({backgroundColor:'white',width:320,bottom:0,height:50,url:'ad.html'});
           win2.add(adview);
    
    function watchFrame(){
    if (adview.url!="file:///android_asset/Resources/ad.html"){
     Ti.API.info(adview.url);
     }else{
        setInterval(watchFrame, 400);
    }
    }
    setInterval(watchFrame, 400);
    

    I just need to confirm that when using a non Public Service Announcement, how many address changes before the final address is set, which i'll then open in a new browser.
    Perhaps, i'll just wait for 3 consecutive calls to be the same address or something similar.

    — answered June 23rd 2010 by Ryan Tregea
    permalink
    0 Comments
  • Posted to pastie

    Another possible solution, this worked for me.

    — answered August 25th 2010 by j J
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.