正如我貼在DFP幫助論壇:https://productforums.google.com/forum/#!topic/dfp/9BsgVtKTU9A
我有工作的解決方案,在那裏我使用jQuery。
if(typeof googletag !== 'undefined' && typeof googletag.pubads !== 'undefined') {
if(adsCloned === false) {
var $dfpIframe = $('#div-gpt-ad-1477269112222-0').find('iframe'); // this is ad id that you use in googletag.defineSlot()
$dfpIframe.each(function (i, v) {
var $clone = $(v).clone();
$(v).replaceWith($clone);
});
adsCloned = true;
}
googletag.pubads().refresh();
}
之前,你必須定義var adsCloned = false;
爲什麼它的工作原理的原因,是當你刷新的頁面加載後插入iframe中(在這種情況下,克隆的iframe)的歷史記錄條目不會添加到IE瀏覽器。
編輯: 如果它不會爲你工作,嘗試刪除,如果statememt:
if(typeof googletag !== 'undefined' && typeof googletag.pubads !== 'undefined') {
var $dfpIframe = $('#div-gpt-ad-1477269112222-0').find('iframe'); // this is ad id that you use in googletag.defineSlot()
$dfpIframe.each(function (i, v) {
var $clone = $(v).clone();
$(v).replaceWith($clone);
});
googletag.pubads().refresh();
}
上面的代碼wont't工作 - 我的錯誤。 但我的工作解決方案是摧毀整個googletag變量並再次調用整個代碼。
DFP腳本首先調用如下(注googletag.pubads()disableInitialLoad();和gads.id = 'dfpHeadScript'。):
// Doubleclick
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.id = 'dfpHeadScript';
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
googletag.cmd.push(function() {
enovatis.dfpSlots.push(googletag.defineSlot('...', [240, 400], 'div-gpt-ad-1').addService(googletag.pubads()));
enovatis.dfpSlots.push(googletag.defineSlot('...', [[960, 100], [750, 100]], 'div-gpt-ad-2').addService(googletag.pubads()));
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
});
googletag.cmd.push(function(){
googletag.pubads().refresh();
});
和刷新廣告的方法是:
var dfpInterval = null;
var $dfpTop = $('#div-gpt-ad-1');
var $dfpLeft = $('#div-gpt-ad-2');
function refreshDfp() {
$dfpTop.empty();
$dfpLeft.empty();
googletag = {};
googletag.cmd = [];
$('#dfpHeadScript').remove();
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.id = 'dfpHeadScript';
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
googletag.cmd.push(function() {
enovatis.dfpSlots.push(googletag.defineSlot('...', [240, 400], 'div-gpt-ad-1').addService(googletag.pubads()));
enovatis.dfpSlots.push(googletag.defineSlot('...', [[960, 100], [750, 100]], 'div-gpt-ad-2').addService(googletag.pubads()));
googletag.pubads().enableSingleRequest();
googletag.pubads().collapseEmptyDivs();
googletag.pubads().disableInitialLoad();
googletag.enableServices();
window.clearInterval(dfpInterval);
dfpInterval = window.setInterval(function(){
if(typeof googletag.pubads !== 'undefined'){
window.setTimeout(function(){
googletag.pubads().refresh();
}, 75);
window.clearInterval(dfpInterval);
}
}, 75);
});
}
我把它稱爲:refreshDfp.apply(window);
,一切正常。 這種方法的唯一缺點是我們每次都會向Google發送更多請求。
是的,很奇怪這個問題還沒有解決。我們現在根本不會在IE中刷新廣告。 – Bodman