Firefox 插件:如何获取地址栏的值?
我正在尝试构建一个 Firefox 插件。谁能告诉我如何获取地址栏的值?
目前我正在使用下面的代码,但我不想在单独的文本框中输入网址。相反,我想从我要输入的地址栏中获取值。
我的代码应该完成剩下的工作。 当前代码从文本框 JavaScript 代码中获取值
:
function Doit()
{
var url = document.getElementById('txtSource').value;
url = url.replace('www.', 'myvalue.whatever.');
var dest = document.getElementById('txtDest');
dest.value = url;
window.open(url,'_newtab');
}
HTML:
<input type="text" id="txtSource"/><br><br>
<input type="button" value="ACDEV" onClick="Doit();"/>
<input type="hidden" id="txtDest">
输出应该是: 当我输入 http://www.something.com 插件应该创建 http://myvalue.something.com 点击插件图标
I am trying to build a firefox addon. Can anyone tell me how can I get the value of address bar ?
currently I am using the below code but I dont want to enter the url in a seperate text box . Instead I want to take value from address bar which i am going to type.
My code should do the rest.
Currently code takes the value from textbox
JavaScript Code:
function Doit()
{
var url = document.getElementById('txtSource').value;
url = url.replace('www.', 'myvalue.whatever.');
var dest = document.getElementById('txtDest');
dest.value = url;
window.open(url,'_newtab');
}
HTML:
<input type="text" id="txtSource"/><br><br>
<input type="button" value="ACDEV" onClick="Doit();"/>
<input type="hidden" id="txtDest">
Output should be:
when I enter http://www.something.com addon should create http://myvalue.something.com on click of addon icon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
document.URL
来完成您的工作。document.URL
或document.location
返回只读字符串。您无法更改document.URL
,但可以更改窗口位置。window.location.href
属性与document.URL
相同,window.location.href
可以用于服务器重定向。Use
document.URL
to get your job done.The
document.URL
ordocument.location
returns a read only string. You can't change thedocument.URL
, but you can change the window location.The
window.location.href
property is the same as thedocument.URL
,window.location.href
can be used for server redirect.使用
location.href
检索值您还应该修改您的替换模式以避免在 URL 上出现意外结果,例如
或
Use
location.href
to retrieve the valueYou also should modify your replace-pattern to avoid unexpected results on URLs like
or
对于插件,您可以使用以下代码从地址栏
Javascript 代码获取 URL:
HTML 代码:
这将生成浏览器当前选项卡上显示的 URL。
For the addon you can use following code to get URL from the address bar
Javascript code:
HTML code:
This will generate the URL presented on the present tab of the browser.