本文介绍了浏览器扩展 - 如何获取当前页面的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个自定义按钮。当我点击它,它应该显示当前页面的URL。我找到答案为document.location或windows.location。但是,都指向本地XUL位置chrome://browser/content/browser.xul而不是原始URL。任何人都可以展示如何做到这一点?
解决方案
$ b
函数getURL {
var currentWindow = Components.classes [ @ mozilla.org/appshell/window-mediator;1\"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow(\"navigator:browser);
var currBrowseSession = currentWindow.getBrowser();
var currURL = currBrowseSession.currentURI.spec;
返回currURL;
}
I am making a custom button. When I click that,it should show the "current page's URL".I found the answer as "document.location" or "windows.location" . But, both points to the local XUL location "chrome://browser/content/browser.xul" not the original URL. Can anybody show how to accomplish this?
解决方案
Try anyone of these.. One should definitely work,
function getURL{
var currentWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
var currBrowseSession = currentWindow.getBrowser();
var currURL = currBrowseSession.currentURI.spec;
return currURL;
}
这篇关于浏览器扩展 - 如何获取当前页面的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!