开场仅使用URL window.open的一个实例 [英] Opening only one instance of url using window.open

查看:276
本文介绍了开场仅使用URL window.open的一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个asp.net网页里面有一个超链接上。单击该超链接时过,是使用JavaScript window.open 打开了一个新的浏览器窗口。我想,如果用户点击此链接多次,那么只有一个窗口被打开,而不是多个窗口。我只是想,当用户点击该超链接多次以突出显示该窗口。我是否需要使用 window.open 来如果URL在浏览器中的任何其他选项卡打开检测?是否有内置该这样我可以用它浏览器兼容性的jQuery插件。

I am working on an asp.net web page which has a hyperlink. when ever that hyperlink is clicked, a new browser window is opened using javascript window.open. I want that If user clicks this link multiple times, then only one window is opened and not multiple windows. I just want that window to be highlighted when user clicks that hyperlink multiple times. Do I need to use window.open to detect if the url is opened in any other tab of the browser ? Is there any jQuery plugin built in for this so that I can use it for browser compatibility.

下面是超链接网址:

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

和这里是code我使用的:

and here is the code I am using:

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");
}

请建议。

推荐答案

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);
}

这篇关于开场仅使用URL window.open的一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆