如何获取e10s插件中的活动标签URL [英] How to get the active tab URL in an e10s add-on

查看:209
本文介绍了如何获取e10s插件中的活动标签URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b 但是

pre> window.gBrowser.selectedBrowser.contentDocument

得到一个 CPOW 错误。

如何获取e10s插件中的活动标签URL的URL位置? / p>

解决方案

环顾可用的对象,并在源代码,它看起来像你应该得到的活动选项卡的URI是:



从目前 nsIURI

  window.gBrowser.currentURI.spec 

对象 window.gBrowser。当前URI 返回一个 nsIURI ,它具有许多可以获取URI的属性,包括:

pre > [nsIURI] .spec //返回URI的字符串表示形式。
[nsIURI] .asciiSpec //与ASCII兼容编码的URI规范。
[nsIURI] .specIgnoringRef //返回没有ref
//(部分在#之后)部分的URI的字符串表示形式。

您也可以获取 nsIURI p>

  window.gBrowser.selectedBrowser._documentURI 

urlbar

当然,您可以将网址从 urlbar


  window.document.getElementById('urlbar') .value 

寻找窗口

上面的所有假设已经将窗口适当地设置为当前活动的窗口。例如,通过执行以下操作:

  //添加/删除/以评论/取消注释代码为您的附加类型。 
/ *附加SDK:
let window = require('sdk / window / utils')。getMostRecentBrowserWindow();
// * /
// *覆盖和引导(来自几乎所有的上下文/范围):
Components.utils.import(resource://gre/modules/Services.jsm ); //服务
let window = Services.wm.getMostRecentWindow(navigator:browser);
// * /


For a toolbar button click, I need to get the URL address of the active tab.

But

window.gBrowser.selectedBrowser.contentDocument

gets a CPOW error.

How can I get the URL location of the active tab URL within an e10s add-on?

解决方案

Looking around at the objects available, and in the source code, it looks like where you should get the URI for the active tab is:

From the current nsIURI:

window.gBrowser.currentURI.spec

The object window.gBrowser.currentURI returns a nsIURI which has a number of properties from which you could get the URI, including:

[nsIURI].spec //Returns a string representation of the URI. 
[nsIURI].asciiSpec //The URI spec with an ASCII compatible encoding. 
[nsIURI].specIgnoringRef //Returns a string representation of the URI without the ref
                         //  (part after the #) portion.

You can also get the nsIURI for the current selected tab as:

window.gBrowser.selectedBrowser._documentURI

From the urlbar:
You could, of course, pull the URL out of the urlbar:

window.document.getElementById('urlbar').value

Finding window:
All of the above assume that you have set window appropriately to the currently active window. For example, by doing something like:

    //  Add/remove a "/" to comment/un-comment the code appropriate for your add-on type.
    /* Add-on SDK:
    let window = require('sdk/window/utils').getMostRecentBrowserWindow();
    //*/
    //* Overlay and bootstrap (from almost any context/scope):
    Components.utils.import("resource://gre/modules/Services.jsm"); //Services
    let window=Services.wm.getMostRecentWindow("navigator:browser");        
    //*/

这篇关于如何获取e10s插件中的活动标签URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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