如何在javascript中打开尚未打开的新选项卡

如何在javascript中打开尚未打开的新选项卡,javascript,mozilla,Javascript,Mozilla,我一直在寻找解决我典型问题的方法,最后我找到了一个,但我需要让它更合适。 我的问题是我想在新的选项卡中打开一个链接,如果它尚未打开,我在Mozilla doc中找到的示例正是我所需要的,但它是在窗口中打开新链接,而不是在选项卡中打开新链接。这里有人可以帮助我如何将此代码更改为在新选项卡中打开链接,而不是在窗口中打开链接 我的代码: <script type="text/javascript"> var windowObjectReference = null; // global v

我一直在寻找解决我典型问题的方法,最后我找到了一个,但我需要让它更合适。 我的问题是我想在新的选项卡中打开一个链接,如果它尚未打开,我在Mozilla doc中找到的示例正是我所需要的,但它是在窗口中打开新链接,而不是在选项卡中打开新链接。这里有人可以帮助我如何将此代码更改为在新选项卡中打开链接,而不是在窗口中打开链接

我的代码:

<script type="text/javascript">
var windowObjectReference = null; // global variable

function openFFPromotionPopup() {
  if(windowObjectReference == null || windowObjectReference.closed)
  /* if the pointer to the window object in memory does not exist
     or if such pointer exists but the window was closed */

  {
    windowObjectReference = window.open("https://jobscane.com/",
   "PromoteFirefoxWindowName", "resizable,scrollbars,status");
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
  }
  else
  {
    windowObjectReference.focus();
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
  };
}
</script>

(...)

<p><a
 href="https://jobscane.com/"
 target="_blank"
 onclick="openFFPromotionPopup(); return false;" 
 title="This link will create a new window or will re-use an already opened one"
>Promote Firefox adoption</a></p>

var windowObjectReference=null;//全局变量
函数openFFPromotionPopup(){
if(windowObjectReference==null | | windowObjectReference.closed)
/*如果指向内存中窗口对象的指针不存在
或者如果该指针存在,但窗口已关闭*/
{
windowObjectReference=window.open(“https://jobscane.com/",
“PromoteFirefoxWindowName”、“可调整大小、滚动条、状态”);
/*然后创建它。新窗口将被创建并
将被带到任何其他窗口的顶部*/
}
其他的
{
windowObjectReference.focus();
/*否则窗口引用必须存在,并且窗口
没有关闭;因此,我们可以将其恢复到任何其他
使用focus()方法打开窗口。无需重新创建
要重新加载引用的资源,请单击窗口或*/
};
}
(...)


要在新选项卡中打开,必须使用旧的解决方法

见此帖:


您可以使用
Anchor
标记而不是
window.open()

试试下面的方法,看看是否有效。此外,问题是,不同的浏览器和用户设置的行为可能会有所不同

<a href={link} target="_blank">Open in tab</a>


这项功能不起作用至少有一个很好的原因——当用户试图关闭选项卡时,可以使用这类代码强制选项卡保持打开状态。。为什么你不能像其他人一样在IFRAME中加载促销内容?您甚至可以使用“lightbox”来显示IFRAME,并使其显示在屏幕的正前方。。。HTML5有许多新的功能,不会让用户感到厌烦。如果你只是想链接到另一个SO问题,你应该投票以重复的方式关闭。