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

发布于 2024-08-19 11:26:24 字数 1880 浏览 9 评论 0原文

我正在使用 nsIWebProgressListener 界面 来了解是否网址已更改。如果有的话我想重写链接。 这是一个片段(从上面的链接的页面底部获取的代码)


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
        }
}

这​​就是发生的情况! 替代文本 http://grab.by/20eP 正如您所看到的,整个浏览器/地址栏/chrome 消失了!

对此有什么帮助吗?

I'm using the nsIWebProgressListener interface to find out if a url has been changed. If it has, I'd like to rewrite the link.
Here's a snippet (code taken from the bottom of the page from the link above)


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);

And a function to handle the change:


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

Here's what happens!
alt text http://grab.by/20eP
As you can see the entire browser/address bar/chrome disappeared!

Any help on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-08-26 11:26:24

简单的:
添加window.content.location

simple:
add window.content.location

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文