1

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?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
user366121
  • 3,203
  • 9
  • 48
  • 69
  • Similar question here => http://stackoverflow.com/questions/1034621/get-current-url-with-javascript – lashleigh Mar 02 '11 at 08: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 Mar 02 '11 at 08:56

1 Answers1

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143