2

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 Answer 1

4

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;
Sign up to request clarification or add additional context in comments.

2 Comments

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: Just return currentPageURl != "about:blank" would return a boolean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.