每隔2分钟在Ionic上通过AdMob展示插页式广告 [英] Show Interstitial Ad via AdMob in Ionic every 2 minutes
问题描述
我在Ionic中使用AdMob外挂程式,使用这段程式码显示Interstital广告:
function initAd
//它将在顶部中心显示智能横幅,使用默认选项
if(AdMob)AdMob.createBanner({
adId:admobid.banner,
bannerId:admobid。横幅,
position:AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow:true,
isTesting:false,
success:function(){
console.log创建');
},
错误: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);
,你应该在 initAdd
function:
function initAd(){//它将在顶部中心显示智能横幅,使用默认选项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(); // !!!在这里添加代码! - 所以,只是粘贴我上面写的:setInterval(window.AdMob.showInterstitial,2 * 60 * 1000); }您可以在此上看到一个简单的setInterval使用方法。 =http://jsfiddle.net/np1cgx6a/ =nofollow> jsFiddle示例:
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);
>
希望这有助于清除一些东西。
I'm using AdMob plugin in Ionic and with this code I show an Interstital ad:
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();
}
Is there a way to show intersitial ad every 2 minutes? Someone told me to add this: setInterval(showInterstitial,1*60*1000)
, but I don't know where to add?
解决方案 If you would like to show it every 2 minutes you should use:
setInterval(window.AdMob.showInterstitial, 2*60*1000);
and you should add it just before the closing bracket of your initAdd
function:
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();
//!!!add the code here!!! - so, just paste what I wrote above:
setInterval(window.AdMob.showInterstitial, 2*60*1000);
}
You can see a simple setInterval usage on this jsFiddle example:
function a(){
alert("hi every 2 seconds");
};
setInterval(a, 2*1000);
The reason why you shouldn't call it like this (note the brackets after a
): setInterval(a(), 2*1000);
is that then your function would be called only once (you would see only one alert popping up). Example on jsFiddle:
function a(){
alert("hi every 2 seconds");
};
setInterval(a(), 2*1000);
Hope this helps clear things a bit.
这篇关于每隔2分钟在Ionic上通过AdMob展示插页式广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文