在Firefox插件中获取当前的浏览器网址 [英] Getting current browser url in Firefox Addon
问题描述
唯一能返回任何东西的东西就是 resource:// jid0-18z0ptaugyu0arjkaoywztggyzg-at-jetpack /
然后是我当前的面板资源。显然这是一个范围问题,但我不知道如何引用实际的浏览器。
window.location.href
我已经尝试了最大的堆栈溢出线程中的所有内容:从Firefox侧边栏扩展中获取当前页面的URL 。
如果有帮助的话,我使用的是Firefox的Addon Builder。
//您需要先使用此服务
var windowsService = Components.classes ['@ mozilla.org/appshell/window-mediator;1 ] .getService(Components.interfaces.nsIWindowMediator);
//表示Firefox最近(活动)实例的窗口对象
var currentWindow = windowsService.getMostRecentWindow('navigator:browser');
//最近的(活动的)浏览器对象 - 这是chrome中的文档框架
var browser = currentWindow.getBrowser();
//包含浏览器中显示地址的所有数据的对象
var uri = browser.currentURI;
//在浏览器中显示的实际完整URL的文本表示
var url = uri.spec;
I within a panel and I want to get the current browser URL. Nothing so far works. Here's what I've tested:
Only thing that even returns anything, I get something like resource://jid0-18z0ptaugyu0arjkaoywztggyzg-at-jetpack/
and then my current panel resource. Obviously this is a scope problem but I don't know how to refer to the actual browser.
window.location.href
I've tried literally everything in the biggest Stack Overflow thread on this: Get current page URL from a firefox sidebar extension. None of them return anything.
If it helps, I am using the Firefox Addon Builder.
// you need to use this service first
var windowsService = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
// window object representing the most recent (active) instance of Firefox
var currentWindow = windowsService.getMostRecentWindow('navigator:browser');
// most recent (active) browser object - that's the document frame inside the chrome
var browser = currentWindow.getBrowser();
// object containing all the data about an address displayed in the browser
var uri = browser.currentURI;
// textual representation of the actual full URL displayed in the browser
var url = uri.spec;
这篇关于在Firefox插件中获取当前的浏览器网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!