views:

50

answers:

1

Hi

I am working on one web application. I am interested in to fetch selected tab URL. I am using Firefox browser.

I achieved this by executing below javascript statements :

/* Get the URL of page which is currently loaded in active tab  */
var currentPageURl = window.top.getBrowser().selectedBrowser.contentWindow.location.href;
alert(currentPageURl);

Above statement work if page is loaded. But if I open's a new tab on Firefox browser (not entered any URL ) and executes above javascript. I am getting about:blank as a result.

I wanted to add such javascript statements which should handle such that if current page is loaded in tab then only gives URL, if page is not loaded then it should return false instead of about:blank

Your suggestions are welcome!!!

Thanks

-Pravin

+1  A: 

Use && or an if statement to check the value:

// return false if about:blank, url if anything else
return currentPageURl != "about:blank" && currentPageURl;

Equivalent of

if (currentPageURl == "about:blank")
    return false;
else
    return currentPageURl;
Andy E
@Andy : this seems fine to me....but is there any boolean value returns from window.top.getBrowser().selectedBrowser.contentWindow.location.href; So that i can catch and validate accordingly instead of comapring with "about:blank" string. - BTW Thanks for quick reply :)
pravin
@pravin: Just `return currentPageURl != "about:blank"` would return a boolean.
Andy E