views:

203

answers:

3

Hello, does anybody know, how to get URI of current page/tab?

A: 

window.location.href holds the URI of the window’s document.

Gumbo
OK, thank you. <pre>content.location.href</pre> show me the URI of the page :)
+2  A: 

This page seems to have what you are looking for

and this one may have more info that you will find useful

phsr
+1  A: 

The accepted answer here is incorrect, but the comment associated with it is a lot closer.

The FAQ linked in phsr's page links to "Getting document of currently selected tab", but Mozilla changed all their links without retaining backwards compatibility, and thus breaking a lot of reference sites.

The correct URL is: https://developer.mozilla.org/en/Extension_Code_Snippets/Tabbed_Browser#Getting_document_of_currently_selected_tab

This document explains how to get the document object as you'd expect to get in web-side Javascript.

Given than, you can easily ask for gBrowser.contentDocument.location.href or content.document.location.href. If your use-case is more complex than a script running on the active tab (eg Your script is running in a pop-up XUL window) then you're best to read the FAQ linked above.

RickMeasham