有关如何实现的一些代码和想法,请参阅此问题中的响应:
https ://stackoverflow.com/a/31187541/4025963
编辑
假设cordova-admob插件,基本上这个想法可能是这个:
<a onclick="showInterstitial()" id="btn_prepare" class="pure-button pure-button-primary">GO TO APP</a>
在你的 js 代码中:
var isAppForeground = true;
var isShowMainOnCloseAd = false;
var isMainAlreadyShown = false;
var isInterstitialAvailable = false;
function showInterstitial() {
if (isInterstitialAvailable) {
admob.showInterstitialAd();
} else {
showMain(function () {
isMainAlreadyShown = true;
});
}
}
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('cordova-admob plugin not ready');
}
}
function onAdLoaded(e) {
if (isAppForeground) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
isInterstitialAvailable = true;
}
}
}
function onAdOpened(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL && !isMainAlreadyShown) {
isShowMainOnCloseAd = true;
}
}
function onAdClosed(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL && isShowMainOnCloseAd) {
isShowMainOnCloseAd = false;
if (!isMainAlreadyShown) {
showMain(function () {
isMainAlreadyShown = true;
});
}
}
}
function onPause() {
if (isAppForeground) {
isAppForeground = false;
}
}
function onResume() {
if (!isAppForeground) {
setTimeout(admob.requestInterstitialAd, 1);
isAppForeground = true;
}
}
function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdOpened, onAdOpened);
document.addEventListener(admob.events.onAdClosed, onAdClosed);
document.addEventListener("pause", onPause, false);
document.addEventListener("resume", onResume, false);
}
function onDeviceReady() {
document.removeEventListener('deviceready', onDeviceReady, false);
initAds();
// request an interstitial
admob.requestInterstitialAd();
}
document.addEventListener("deviceready", onDeviceReady, false);