请看这里:https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd,有一个关于如何显示插页式广告的完整示例:
基本上,您要做的就是在设备准备就绪时使用autoShowInterstitial: false、requestInterstitialAd 开始广告,在点击事件发生时显示此预加载的插页式广告,并在显示最后一个插页式广告时重新加载新的插页式广告:
var isAppForeground = true;
var isInterstitialReady = true;
function onAdLoaded(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialReady = true;
}
}
}
function onAdClosed(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialReady = false;
admob.requestInterstitialAd();
}
}
}
function onPause() {
if (isAppForeground) {
admob.destroyBannerView();
isAppForeground = false;
}
}
function onResume() {
if (!isAppForeground) {
setTimeout(admob.createBannerView, 1);
setTimeout(admob.requestInterstitialAd, 1);
isAppForeground = true;
}
}
// optional, in case respond to events
function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdClosed, onAdClosed);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
}
function initAds() {
if (admob) {
var adPublisherIds = {
ios : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
},
android : {
banner : "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitial : "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII"
}
};
var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;
admob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
autoShowInterstitial: false
});
registerAdEvents();
} else {
alert('AdMobAds plugin not ready');
}
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
initAds();
// display a banner at startup
admob.createBannerView();
// request an interstitial
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);
然后在你的按钮事件中:
$("#myButton").on( "click", function() {
if (isInterstitialReady) {
admob.showInterstitialAd();
} else {
// We do not have an interstitial ready, try to request a new one
// It can be mainly because of 3 reasons:
// - Can't connect with Admob (i.e. no connectivity available)
// - Admob does not have available any interstitials at this moment
// - Not enought time between last requestInterstitialAd() and myButton.click()
admob.requestInterstitialAd();
}
});