0

我正在处理一个带有超链接的 asp.net 网页。每当单击该超链接时,就会使用 javascript 打开一个新的浏览器窗口window.open。我希望如果用户多次单击此链接,则只打开一个窗口而不是多个窗口。我只想在用户多次单击该超链接时突出​​显示该窗口。我是否需要使用window.open来检测 url 是否在浏览器的任何其他选项卡中打开?是否有为此内置的任何 jQuery 插件,以便我可以将其用于浏览器兼容性。

这是超链接网址:

<a onclick="addClick()" href="javascript:void(0)">
                    New</a>

这是我正在使用的代码:

function addClick() {
    var ID = jQuery("#ID").val();
    var PSSWD = jQuery("#PSSWD").val();
    var ACCID = jQuery("#ACCID").val();
    var PASSWDINT = jQuery("#PASSWDINT").val();

    window.open("LoginAPI?ID=" + encodeURIComponent(ID) + "&PSSWD=" + encodeURIComponent(PSSWD) + "&ACCID=" + encodeURIComponent(ACCID) + "&PASSWDINT=" + encodeURIComponent(PASSWDINT) + "", "LoginAPI");
}

请建议。

4

4 回答 4

3

尝试

window.open("<url>", "<window name>");

这应该始终在同一个窗口中打开。请参阅参考资料

于 2013-06-07T06:32:44.633 回答
1

HTML:

<a href="http://www.someurl.com" onclick="openwindow.call(this); return false;">open window</a>

var wins = {};
function openwindow(){
    var url = this.href;
    if(typeof wins[url] === 'undefined' || wins[url].closed)
        wins[url] = window.open(url);
}
于 2013-06-07T06:33:27.707 回答
0
<script>


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("http://www.spreadfirefox.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>
<a href="javascript:void(0);" onclick="openFFPromotionPopup()">click here</a>

检查参考https://developer.mozilla.org/en-US/docs/Web/API/window.open

于 2013-06-07T06:58:28.033 回答
0

要在 HTML 页面中仅打开一个弹出窗口实例,windowName请使用window.open method.
例如

window.open('http://www.abc.com') 

每次用户单击包含 window.open 代码的链接时,都会打开一个新窗口。
相比之下,

window.open('http://www.abc.com','abc') 

无论用户点击链接多少次,都只会打开一个窗口实例。

您还可以focus使用下面使用的功能

<script language="javascript" type="text/javascript">
<!--
function popitup(url) {
    newwindow=window.open(url,'name','height=200,width=150');
    if (window.focus) {newwindow.focus()}

      if (!newwindow.closed) {newwindow.focus()}
    return false;
}

// -->
</script>

编辑 1

<a onclick="return addClick()" href="javascript:void(0)">New</a>

这是我正在使用的代码:

function addClick() {
    var ID = jQuery("#ID").val();
    var PSSWD = jQuery("#PSSWD").val();
    var ACCID = jQuery("#ACCID").val();
    var PASSWDINT = jQuery("#PASSWDINT").val();

    window.open("LoginAPI?ID=" + encodeURIComponent(ID) + "&PSSWD=" + encodeURIComponent(PSSWD) + "&ACCID=" + encodeURIComponent(ACCID) + "&PASSWDINT=" + encodeURIComponent(PASSWDINT) + "", "LoginAPI");
    return false;
}
于 2013-06-07T06:50:16.880 回答