【问题标题】:Monitoring current tab location.href in Firefox在 Firefox 中监视当前选项卡 location.href
【发布时间】:2012-05-17 02:37:55
【问题描述】:

我想在 Firefox 浏览器中监控用户活动,我需要知道它在当前选项卡中的 location.href。为此,我使用 content.location.href ,但是当这个 location.href 发生变化时我需要代码。我需要知道我应该监听哪些事件以及浏览器中的哪些对象。

我的一些代码:

window.addEventListener("load", function load(event){
    window.removeEventListener("load", load, false);
    myExtension.init();
},false);

var myExtension = {
  init: function() {
    var appcontent = document.getElementById("appcontent");
    appcontent.addEventListener("blur", myExtension.onPageBlur, true);
    appcontent.addEventListener("load", myExtension.onPageLoad, true);
    appcontent.addEventListener("focus", myExtension.onPageFocus, true);
  },

  onPageBlur: function () {
    // Doing something when there is no focus
  },

  onPageFocus: function(aEvent) {
    // Doing something when we get focus
  },

  onPageLoad: function(aEvent) {
    // Doing something on page load
  }
};

此代码有效,但有一些不受欢迎的行为,当您单击浏览器的位置栏时,会触发 blur 事件,如果 location.href 更改(焦点和加载)很难使用 location.href事件触发),在保存用户活动的数据时需要一些返工来优化

我需要代码具有这种行为:

  • 适用于选项卡选择
  • 适用于选项卡 location.href 更改
  • 适用于浏览器的多个窗口

提前谢谢你。

【问题讨论】:

    标签: javascript firefox firefox-addon


    【解决方案1】:

    为此,您应该是using a progress listener。每次当前选项卡的位置更改时都会调用您的onLocationChange,您只需查看aURI.spec。相同的方法用于更新 Firefox 中的地址栏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-24
      相关资源
      最近更新 更多