我一直在寻找解决我的典型问题的方法,最后我找到了一个,但我需要让它更合适。 我的问题是我想在新选项卡中打开一个链接,如果它还没有打开,我从 Mozilla 文档中找到的示例正是我需要的,但它是在窗口中而不是在选项卡中打开新链接吗 这里有人可以帮我如何更改此代码以在新选项卡中而不是窗口中打开链接
我的代码 :
<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>
要在新选项卡中打开,您必须使用旧的解决方法。
请参阅此帖子:
使用 JavaScript 在新选项卡(而不是新窗口(中打开 URL
您可以使用Anchor
标签代替window.open()
尝试类似以下内容,看看它是否有效。此外,问题是行为可能因浏览器和用户设置而异。
<a href={link} target="_blank">Open in tab</a>