在javascript中识别Firefox浏览器的选定标签URL [英] Identify selected tab URL of firefox browser in javascript
问题描述
我有兴趣获取选定的标签网址。我使用Firefox浏览器。
$ b
我通过执行下面的javascript语句实现了这一点:
/ *获取当前装载在活动标签* /
变种currentPageURl = window.top.getBrowser()页的URL selectedBrowser.contentWindow.location.href。
alert(currentPageURl);
如果页面被加载,但是,如果我打开Firefox浏览器(不输入任何URL)的新标签,并执行上面的JavaScript。我得到 about:blank 作为结果。
我想添加这样的JavaScript语句应该处理,如果当前页面加载标签,然后只提供URL,如果页面没有加载,那么它应该返回false而不是about:blank
欢迎您的建议!
由于
-Pravin
&&
或 if 语句来检查值: //如果返回false,则返回false:空白,url(如果有的话)
return currentPageURl!=about:blank&& currentPageURl;
相等于
if(currentPageURl ==about:blank)
return false;
else
返回currentPageURl;
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
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;
这篇关于在javascript中识别Firefox浏览器的选定标签URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!