【问题标题】:Open link in new tab in firefox-extension在 Firefox 扩展的新选项卡中打开链接
【发布时间】:2011-02-24 20:36:25
【问题描述】:

我开发了一个 webapp 来将它用作 Firefox 扩展。在 Firefox 中,我将它包含在这样的 iframe 中

<iframe src="http://mywebapp.com" flex="2" id="browserTable" name="table_frame"/>

现在我想在我的应用程序中添加一些传出链接。如果我只使用普通的链接标记,比如

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

链接在空间很小的 iframe 中打开,因为它位于侧边栏中。有什么方法可以在主浏览器窗口的新标签页中打开它?

【问题讨论】:

    标签: javascript firefox-addon


    【解决方案1】:

    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>
    

    EDIT我们在cmets讨论后做了一些研究,发现了这个sn-p:

    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 环境不是我可以轻松地试验扩展开发的环境,我不想改变任何东西来尝试。

    【讨论】:

    • hm 那打开一个新的ff窗口,想有tab,你觉得这可能吗?也许用 css3 :D w3.org/TR/2004/WD-css3-hyperlinks-20040224 去看看这个
    • 新窗口??世界卫生大会?不应该是。这可能会受到 Firefox 中客户端选项的影响,检查工具->选项,在“选项卡”选项卡上有一系列复选框。一个标题为“改为在选项卡中打开新窗口”。这是检查吗?如果没有,这就是它打开一个新窗口的原因。如果以这种方式配置了客户端选项,则无法“强制”用户打开选项卡。否则,目标属性应该打开一个新选项卡。
    • 如果我们可以集中打开的标签页会很棒
    • 最后一行应该这样做。我想它不是。让我知道...我可以通读文档并尝试了解如何操作。再说一遍 - 我是为了我自己而好奇,而不是为了测试它。豚鼠给我! :)
    • 仅供参考 target="_content" 应该在当前浏览器选项卡中打开一个侧边栏链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 2011-01-25
    • 1970-01-01
    相关资源
    最近更新 更多