在Firefox扩展中如何在新标签页中打开链接

3
我已经开发了一个Web应用程序,可以将其用作Firefox扩展。在Firefox中,我使用像这样的iframe进行包含:
<iframe src="http://mywebapp.com" flex="2" id="browserTable" name="table_frame"/>

现在我想在我的应用程序中添加一些外部链接。如果我只是使用普通的链接标记,例如:
<a href="http://mywebapp.com/contact">Contact</a>

该链接在小的 iframe 中打开,因为它在侧边栏里。有没有办法在浏览器的主窗口中以新标签页的方式打开它?

1个回答

7

target属性允许您指定在哪个窗口中打开链接。您可以在属性中放置这些特殊关键字:

    _blank - new window
    _self - same window (default)
    _parent - the window which opened the current window, or the parent frame in a frameset
    _top - overload the entire page, usually used in a frame context 
   "string" - in the window with an id of "string", or a new window if "string" is not the id of a current window

那么,这是您的HTML:

<a href="http://mywebapp.com/contact" target="_blank">Contact</a>

编辑 在评论区的讨论之后,我做了一些研究,并找到了以下代码片段:

var myUrl = "http://mesh.typepad.com";
var tBrowser = top.document.getElementById("content");
var tab = tBrowser.addTab(myUrl);
// use this line to focus the new tab, otherwise it will open in background
tBrowser.selectedTab = tab;

来源:http://mesh.typepad.com/blog/2004/11/creating_a_new_.html

如果可以的话,请告诉我......我自己也很好奇,但是我的当前FF环境不适合进行扩展开发实验,我不想更改设置来尝试。


嗯,这会打开一个新的火狐浏览器窗口,我想要一个选项卡,你觉得这可能吗?也许可以用CSS3 :D http://www.w3.org/TR/2004/WD-css3-hyperlinks-20040224/ 我来看看。 - DarkLeafyGreen
一个新窗口??什么?不应该出现这种情况。这可能受到Firefox客户端选项的影响,请检查“工具”->“选项”,在“标签”选项卡上有一系列复选框。其中一个标题为“在选项卡中打开新窗口”。这个选项被选中了吗?如果没有,那就是为什么它会打开一个新窗口。如果用户的客户端选项是这样配置的,就没有办法“强制”用户打开一个选项卡。否则,目标属性应该打开一个新选项卡。 - Chris Baker
如果我们能够聚焦打开的选项卡就太好了。 - DarkLeafyGreen
最后一行应该做到这一点。我觉得没有吧。让我知道...我可以阅读文档并尝试找出如何做到这一点。再次强调 - 我是出于自己的好奇心,而不是为了测试而设置的。请替我试验吧! :) - Chris Baker
FYI target="_content" 应该使侧边栏链接在当前浏览器标签页中打开。 - Neil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接