我正在使用Firefox扩展。为此,我需要当前的URL。我尝试了两种可能性,结果如下:document.URL vs location.href>无结果
location.href > chrome://browser/content/browser.xul
document.URL > undefined
如果单击菜单按钮,则会在事件中调用它们。为什么它不起作用?
我正在使用Firefox扩展。为此,我需要当前的URL。我尝试了两种可能性,结果如下:document.URL vs location.href>无结果
location.href > chrome://browser/content/browser.xul
document.URL > undefined
如果单击菜单按钮,则会在事件中调用它们。为什么它不起作用?
您正在访问Firefox的DOM,而不是网页的DOM。
要获取当前网页的window
元素,可以使用window.content
。
所以你可以通过window.content.location.href
得到位置。
thx男人它现在的作品。 – user366121 2011-03-02 08:59:09
或者window.content.document.URL,无论哪种方式 – MatrixFrog 2011-03-03 18:21:40
类似的问题在这里=> http://stackoverflow.com/questions/1034621/get-current-url-with-javascript – lashleigh 2011-03-02 08:37:55
@lashleigh:OP知道已经有关这些方法。问题在于上下文不同。也许它是重复的,但不是你连接的问题。 – 2011-03-02 08:56:55