最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - document.URL vs location.href > no results - Stack Overflow

programmeradmin4浏览0评论

I am working on a Firefox extension. For this I need the current URL. I tried both possibilities with the following result:

location.href   >  chrome://browser/content/browser.xul
document.URL    >  undefined

They are called in the event if a menu button is clicked. Why is it not working?

I am working on a Firefox extension. For this I need the current URL. I tried both possibilities with the following result:

location.href   >  chrome://browser/content/browser.xul
document.URL    >  undefined

They are called in the event if a menu button is clicked. Why is it not working?

Share Improve this question edited Mar 2, 2011 at 8:55 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Mar 2, 2011 at 8:14 user366121user366121 3,30110 gold badges51 silver badges69 bronze badges 2
  • Similar question here => stackoverflow./questions/1034621/… – lashleigh Commented Mar 2, 2011 at 8:37
  • @lashleigh: The OP knows already about these methods. The problem is that the context is different. Maybe it is a duplicate, but not of the question you linked to. – Felix Kling Commented Mar 2, 2011 at 8:56
Add a ment  | 

1 Answer 1

Reset to default 7

You are accessing Firefox's DOM, not the web page's one.

To get the window element for the current web page, you can use window.content.

So you can get the location via window.content.location.href.

发布评论

评论列表(0)

  1. 暂无评论