簡體   English   中英

在Chrome上檢測此事件:更改網址更改而不重新加載

[英]Detect this event on Chrome: change of URL change without reloading

我有一個網站可以更改URL而無需在Chrome上使用以下命令重新加載:

window.history.pushState(“object or string”, “Title”, “/new-url”);

有沒有辦法從Javascript中檢測到這樣的事件? 我試過這個,但它不起作用:

$(window).bind('hashchange', function() {
    alert("CHANGED!!");
});  

僅適用於Chrome擴展程序

鑒於:

var stateObj = { foo: "bar" };
history.pushState(stateObj, "page 2", "yourwebsite.com/page2");

你可以用這個來檢測它:

chrome.webNavigation.onHistoryStateUpdated.addListener(function(e) {
        console.log(e);
      }, {url: [{hostEquals: 'yourwebsite.com'});

暫無
暫無

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

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