如何聆听历史事件,如“回去”,“去下一个”在Chrome扩展中? [英] How to listen to history events like "go back", "go next" in Chrome extension?

查看:75
本文介绍了如何聆听历史事件,如“回去”,“去下一个”在Chrome扩展中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我只找到一种方法来使用以下方法来收听重新加载事件:

 <$ c (详细信息){
if(details.frameId == 0){
if(details.transitionType ==reload){
//做某事
}
}
});

关于返回和下一个事件呢?我在Chrome浏览器中寻找Firefox的 nsISHistoryListener 替代方案。


$ b

编辑:已提交向Chromium发送功能请求

$ b $您可以使用window.beforeunload事件来捕获用户何时打算导航到另一个页面(当使用后退和前进按钮时会触发该页面) 。

  window.onbeforeunload = function(){
//做某事
};

使用 onbeforeunload



更多信息:单击后退按钮时是否存在跨浏览器onload事件?


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆