Firefox 插件:如何获取地址栏的值?

发布于 2024-12-23 03:40:08 字数 808 浏览 2 评论 0原文

我正在尝试构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多情癖 2024-12-30 03:40:08

使用 document.URL 来完成您的工作。

document.URLdocument.location 返回只读字符串。您无法更改 document.URL,但可以更改窗口位置。

window.location.href属性与document.URL相同,window.location.href可以用于服务器重定向。

Use document.URL to get your job done.

The document.URL or document.location returns a read only string. You can't change the document.URL, but you can change the window location.

The window.location.href property is the same as the document.URL, window.location.href can be used for server redirect.

星星的轨迹 2024-12-30 03:40:08

使用 location.href 检索值

您还应该修改您的替换模式以避免在 URL 上出现意外结果,例如

http://something.www.anotherthing.com

http://something.com/www.htm

Use location.href to retrieve the value

You also should modify your replace-pattern to avoid unexpected results on URLs like

http://something.www.anotherthing.com

or

http://something.com/www.htm
大海や 2024-12-30 03:40:08

对于插件,您可以使用以下代码从地址栏

Javascript 代码获取 URL:

function Doit(){
   var link = window.top.getBrowser().selectedBrowser.contentWindow.location.href;
   alert (link); 
}

HTML 代码:

<div onclick = "Doit()">Generate URL</div>

这将生成浏览器当前选项卡上显示的 URL。

For the addon you can use following code to get URL from the address bar

Javascript code:

function Doit(){
   var link = window.top.getBrowser().selectedBrowser.contentWindow.location.href;
   alert (link); 
}

HTML code:

<div onclick = "Doit()">Generate URL</div>

This will generate the URL presented on the present tab of the browser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文