如何聆听历史事件,如“回去”,“去下一个”在Chrome扩展中? [英] How to listen to history events like "go back", "go next" in Chrome extension?
问题描述
现在,我只找到一种方法来使用以下方法来收听重新加载事件:
<$ c (详细信息){
if(details.frameId == 0){
if(details.transitionType ==reload){
//做某事
}
}
});
关于返回和下一个事件呢?我在Chrome浏览器中寻找Firefox的 nsISHistoryListener
替代方案。
$ b
编辑:已提交向Chromium发送功能请求。
$ b $您可以使用window.beforeunload事件来捕获用户何时打算导航到另一个页面(当使用后退和前进按钮时会触发该页面) 。 window.onbeforeunload = function(){
//做某事
};
使用 onbeforeunload $时无法获得目标目的地c $ c>。
For now, I've only found a way to listen to "reload" event using:
chrome.webNavigation.onCommitted.addListener(function(details) {
if (details.frameId == 0) {
if (details.transitionType == "reload") {
// do something
}
}
});
What about "go back" and "go next" events? I'm looking for a Firefox's nsISHistoryListener
alternative in Chrome.
Edit: Submitted a feature request to Chromium.
You could use the window.beforeunload event to capture when a user intends to navigate to another page (which would be triggered when using the back and forward buttons).
window.onbeforeunload = function () {
// do something
};
There is no way to get the target destination when using onbeforeunload
.
More info here: Is there a cross-browser onload event when clicking the back button?
这篇关于如何聆听历史事件,如“回去”,“去下一个”在Chrome扩展中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!