簡體   English   中英

History.js在內容腳本中不起作用

[英]History.js doesn't work in content script

我嘗試在Google Play商店的內容腳本中使用history.js,但是當狀態更改嘗試在清單中使用適配器綁定方法時,該功能未執行:

"js": [
        "js/jquery/jquery.js",
        "js/jquery.knob.js",
        "js/jquery.history.js", 
        "src/inject/inject.js"
      ]

然后在內容腳本中

History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
    var State = History.getState(); // Note: We are using History.getState() instead of event.state
    alert();
});

沒事

而且這個解決方案也不起作用

 (function(history){
    var pushState = history.pushState;
    history.pushState = function(state) {
        if (typeof history.onpushstate == "function") {
            history.onpushstate({state: state});
        }
        // ... whatever else you want to do
        // maybe call onhashchange e.handler
        return pushState.apply(history, arguments);
    }
})(window.history);


history.onpushstate=function(){alert()}

我認為這可能與內容腳本的運行范圍有關

問題在於內容腳本和頁面的窗口對象不同,因此這引起了問題。 到目前為止,我還沒有找到在Chrome內容腳本中使用history.js的方法。 我使用了變異觀察器,即檢查DOM子樹更改來解決問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM