4

我目前是使用pushstate進行頁面重置的網站上的開發人員。Google DFP廣告管理系統刷新廣告會移除Internet Explorer 10中的window.history堆棧

該網站使用谷歌DFP廣告,這刷新每個頁面轉換/路線上

我在Internet Explorer中

我在注意到一個問題,Windows 7中,IE10

googletag.pubads().refresh(GOOGLE_ADS); 

會的window.history棧上刪除條目,從而導致使用後退按鈕有不正確的條目。

快速示例

添加條目到歷史堆棧

console.log(window.history.length) // 3 

window.history.pushState({}, '標題', '/ PAGE_1');
window.history.pushState({},'title','/ page_2');
window.history.pushState({},'title','/ page_3');
window.history.pushState({},'title','/ page_4');

console.log(window.history.length) // 7 

刷新廣告

googletag.pubads().refresh(GOOGLE_ADS); 

檢查歷史長度同樣

console.log(window.history.length) // 3 

如果我是按後退按鈕,它會轉到頁之前登陸頁面。

其他人在IE中注意到這個問題? 看看DFP廣告管理系統源代碼,它會多次引用window.history。

回答

2

我有完全相同的問題,即使在帶有不同域的iframe中運行廣告仍會導致歷史記錄丟失。我認爲這與IE處理iframe src作爲歷史事件有關,但基本上使用谷歌廣告完全打破IE中的pushstate。我發現解決的唯一方法是不使用Google廣告。

+0

是的,很奇怪這個問題還沒有解決。我們現在根本不會在IE中刷新廣告。 – Bodman

1

我遇到了與IE10和IE11相同的問題 - 非常令人失望。

爲了什麼它的價值我曾提出與微軟的錯誤,可以在這裏看到:

https://connect.microsoft.com/IE/feedbackdetail/view/979564/ie-pushstate-history-is-corrupted-by-google-adsense-google-dpf-doubleclick-for-publishers-advertising

如果你有時間,添加您談到的錯誤,給它更多的重量邁向充滿希望的修復。

亞當

+0

MS小組迴應要求提供PoC,您可以回覆他們嗎?自那以後沒有進一步的行動。 –

2

我們有完全相同的問題。在IE10和IE11中,如果您使用DFP,推送狀態幾乎沒有用處。

但是,我們確實想出了一個解決方案。這並不漂亮,但它的工作原理。

不是加載廣告,而是插入iframe。在該iframe中,廣告像往常一樣加載。然而,refresh() - 方法不能在iframe中使用,同樣的問題仍然會發生。但是,當廣告加載到iframe中時,您可以執行的操作是刷新整個iframe。通過這樣做,廣告被刷新並且pushstate功能將保持不變。

很討厭,但它的作品。由於在iframe中加載廣告的原因很多,我們只在IE10和IE11中執行此操作。

0

正如我貼在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發送更多請求。

相關問題