我的网站有一些视频广告。视频广告显示后(发生 ima.adevent.type.complete),游戏通过以下代码获得键盘焦点。但是,如果通过单击跳过按钮跳过视频广告,则不会正确地为游戏提供焦点,这意味着 google.ima.AdEvent.Type.SKIPPED 的情况发生在下面的代码中。
case google.ima.AdEvent.Type.SKIPPED:
case google.ima.AdEvent.Type.COMPLETE:
// This event indicates the ad has finished - the video player
// can perform appropriate UI actions, such as removing the timer for
// remaining time detection.
if (ad.isLinear()) {
clearInterval(intervalTimer);
}
focusWhenReady = function () {
doc = iframe.contentDocument || iframe.contentWindow.document;
if (doc.readyState == "complete") {
iframe.contentWindow.focus();
console.log('code comes here in both cases ...');
} else {
setTimeout(focusWhenReady, 200)
}
}
setTimeout(focusWhenReady, 100);