我在Ionic中使用AdMob插件,并使用此代码显示了一个Interstital广告:
function initAd(){ // it will display smart banner at top center,using the default options if(AdMob) AdMob.createBanner( { adId: admobid.banner,bannerId: admobid.banner,position: AdMob.AD_POSITION.BottOM_CENTER,autoShow: true,isTesting: false,success: function() { console.log('banner created'); },error: function() { console.log('Failed to create banner'); } }); window.AdMob.prepareInterstitial({ adId:admobid.interstitial,autoShow:false }); window.AdMob.showInterstitial(); }
有没有办法每2分钟显示一个部分广告?有人告诉我添加这个:setInterval(showInterstitial,1 * 60 * 1000),但我不知道在哪里添加?
解决方法
如果您想每2分钟显示一次,您应该使用:
setInterval(window.AdMob.showInterstitial,2*60*1000);
function initAd(){ // it will display smart banner at top center,using the default options if(AdMob) AdMob.createBanner( { adId: admobid.banner,position:AdMob.AD_POSITION.BottOM_CENTER,success: function(){ console.log('banner created'); },error: function(){ console.log('Failed to create banner'); } } ); window.AdMob.prepareInterstitial( {adId:admobid.interstitial,autoShow:false} ); window.AdMob.showInterstitial(); //!!!add the code here!!! - so,just paste what I wrote above: setInterval(window.AdMob.showInterstitial,2*60*1000); }
您可以在此jsFiddle example上看到一个简单的setInterval用法:
function a(){ alert("hi every 2 seconds"); }; setInterval(a,2*1000);
你之所以不应该这样称呼它(注意a之后的括号):setInterval(a(),2 * 1000);那么你的函数只会被调用一次(你会看到只弹出一个警告). jsFiddle的例子:
function a(){ alert("hi every 2 seconds"); }; setInterval(a(),2*1000);
希望这有助于清除一些事情.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。