从firefox侧边栏扩展中获取当前页面的URL [英] Get current page URL from a firefox sidebar extension

查看:128
本文介绍了从firefox侧边栏扩展中获取当前页面的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为Firefox编写了一个边栏扩展,需要一种方法来获取当前页面的URL,以便我可以在数据库中检查它并显示结果。我怎样才能做到这一点?

I'm writing a sidebar extension for Firefox and need a way to get the URL of the current page so I can check it against a database and display the results. How can I do this?

推荐答案

window.top.getBrowser().selectedBrowser.contentWindow.location.href;

可能工作,否则我认为您需要使用:

might work, otherwise I think you need to use:

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIWebNavigation)
                   .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                   .rootTreeItem
                   .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                   .getInterface(Components.interfaces.nsIDOMWindow);

mainWindow.getBrowser().selectedBrowser.contentWindow.location.href;

这篇关于从firefox侧边栏扩展中获取当前页面的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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