firefox插件中的window.location.replace删除整个chrome!

时间:2010-01-27 08:49:00

标签: javascript firefox-addon xul

我正在使用nsIWebProgressListener interface来查看网址是否已更改。如果有,我想重写链接。 这是一个片段(代码取自上面链接的页面底部)


var myExt_urlBarListener = {
  QueryInterface: function(aIID)
  {
   if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
       aIID.equals(Components.interfaces.nsISupports))
     return this;
   throw Components.results.NS_NOINTERFACE;
  },

  onLocationChange: function(aProgress, aRequest, aURI)
  {
    myExtension.processNewURL(aURI);
  },

  onStateChange: function(a, b, c, d) {},
  onProgressChange: function(a, b, c, d, e, f) {},
  onStatusChange: function(a, b, c, d) {},
  onSecurityChange: function(a, b, c) {}
};

var myExtension = {
  oldURL: null,

  init: function() {
    // Listen for webpage loads
    gBrowser.addProgressListener(myExt_urlBarListener,
        Components.interfaces.nsIWebProgress.NOTIFY_LOCATION);
  },

  uninit: function() {
    gBrowser.removeProgressListener(myExt_urlBarListener);
  },

  processNewURL: function(aURI) {
    if (aURI.spec == this.oldURL)
      return;

    // now we know the url is new...
    start_work(aURI.spec);
    this.oldURL = aURI.spec;
  }
};

window.addEventListener("load", function() {myExtension.init()}, false);
window.addEventListener("unload", function() {myExtension.uninit()}, false);

以及处理变更的功能:


function start_work(url)
{
    result = check(url);
    if (result) {
            setCookie('bws', 'true', 1, '/');
            window.location = result; // or window.location.replace, doesn't matter
        }
}

这是发生了什么! alt text http://grab.by/20eP 如您所见,整个浏览器/地址栏/ chrome消失了!

对此有何帮助?

1 个答案:

答案 0 :(得分:2)

简单: 添加window.content.location