【发布时间】:2018-09-22 04:52:49
【问题描述】:
我一直在寻找解决我的典型问题的方法,最后我找到了,但我需要让它更合适。 我的问题是我想在新的 tab 中打开一个链接,如果它还没有打开,我从 Mozilla doc 找到的例子正是我需要的,但它正在打开一个 中的新链接window 不在 tab 中有人可以帮我如何更改此代码以在新 tab 中打开链接,而不是 window
我的代码:
<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>
【问题讨论】:
-
这个功能不起作用至少有一个很好的理由——这样的代码可以用来强制标签在用户试图关闭它们时保持打开。为什么你不能只加载促销像其他人一样的 IFRAME?您甚至可以使用“灯箱”来显示 IFRAME,并使其看起来像在屏幕前弹出一样...... HTML5 有许多新功能,不会让用户无所适从。
标签: javascript mozilla