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
1 Answer
Reset to default 7You 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
.