Firefox 侧边栏扩展链接已加载到新的浏览器选项卡中。 如何?

发布于 2024-07-13 07:56:13 字数 293 浏览 5 评论 0原文

我有一个 friefox 侧边栏扩展。 如果通过单击工具栏图标打开它,我会加载一个网页(我编写的)。 现在,如果用户单击网页上的链接(已加载到侧边栏中),我希望链接的网页在主窗口的新选项卡中打开。 我在网页标记中尝试使用此方法:

<a target="_content" href="http://www.google.com">Google</a>

但是链接在具有焦点的选项卡中打开,而不是在新选项卡中打开。

请帮忙。

谢谢。

I have a friefox sidebar extension. If its opened by clicking on the toolbar icon I load it with a webpage ( that I have authored ). Now, if the user clicks on the link on the webpage ( thats loaded into the sidebar ) I want the linked webpage to open up in a new tab of the main window. I tried with this in my webpage markup:

<a target="_content" href="http://www.google.com">Google</a>

But the link opens up in the tab that has focus and not in a new tab.

Please help.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

寂寞美少年 2024-07-20 07:56:13

如果您改用 target="_blank",FF(版本 3)应该为其打开一个新选项卡。 还没有从侧边栏尝试过,但值得一试。

If you use target="_blank" instead, FF (version 3) should open a new tab for it. Haven't tried it from a sidebar, but it's worth giving a shot.

醉态萌生 2024-07-20 07:56:13

实际上,无法将网页(其链接位于加载到侧边栏扩展中的另一个网页中)加载到浏览器中的新选项卡上。 唯一的方法是使用 javascript。 这必须在特权条件下执行(意味着作为扩展的一部分),如下所示:

gBrowser.addTab("http://www.google.com/");

编辑:

上述添加浏览器选项卡的技术在这种情况下不起作用。 根据这篇文章,在侧边栏中运行的代码无法访问主窗口。 因此,在使用 gBrowser 之前,我首先访问了浏览器窗口。 以下是从我使用的网站上获取的代码,并且工作正常:

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);

在访问浏览器窗口后,我通过 getBrowser 函数访问 gBrowser,如下所示:

mainWindow.getBrowser().addTab("http://www.google.com/");

在主窗口浏览器中打开一个新选项卡。

Actually, there is no way to load a webpage ( whose link was in another webpage loaded into the sidebar extension ) onto a new tab in the browser. The only way is to use javascript. That has to execute under privileged conditions ( meaning as part of an extension ) like below:

gBrowser.addTab("http://www.google.com/");

EDIT:

The above technique of adding a browser tab did not work in this case. According to this article code running in the sidebar does not have access to the main window. So first up I got access to the browser window before using gBrowser. Here is the code taken from the website that I used and works properly:

var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIWebNavigation)
.QueryInterface(Components.interfaces.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindow);

After I got access to the browser window I accessed gBrowser through the getBrowser function like below:

mainWindow.getBrowser().addTab("http://www.google.com/");

The opens up a new tab in the main window browser.

℡寂寞咖啡 2024-07-20 07:56:13
<a href="http://www.google.com" target="new">Google</a>

这更取决于所使用的浏览器。 Firefox 和 Opera,以及我确信最新的 IE,都会将“新窗口”显示为新选项卡,除非用户首选项另有指定。

<a href="http://www.google.com" target="new">Google</a>

This is more dependent on the browser that is being used. Firefox and Opera, and I'm sure the newest IE, display "new windows" as a new tab unless otherwise specified by user preference.

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