简体   繁体   English

使用JavaScript的多个弹出窗口

[英]Multiple popup windows using javascript

i am developing a chat application i need a javascript function to open seperate window for each online users now i am using following javascript code 我正在开发一个聊天应用程序,我需要一个javascript函数来为每个在线用户打开单独的窗口,现在我正在使用以下javascript代码

var myWindow;

function openWindow(url)  
{
var width = 700;
var height = 500;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable=no,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
myWindow = window.open(url, "welcome", windowFeatures);

}

and i have called this function in code behind as follows 我已经在后面的代码中调用了此函数,如下所示

<a href='javascript:void(0)' onclick=openWindow('newWindow.aspx?id=" & Id & "')>  </a>

here the id is users ID but new window is replaced in same window where i am doing wrong please guide me Thanks 这里的ID是用户ID,但是新窗口在我做错的同一窗口中被替换,请指导我谢谢

从函数上方删除var myWindow并将其放在函数内部。

You create a window called "welcome" when you run the function for the first time. 首次运行该函数时,将创建一个名为“ welcome”的窗口。 Subsequent calls replace the content, because a window called "welcome" already exists. 后续调用将替换内容,因为已经存在一个名为“欢迎”的窗口。 Your names need to be unique . 您的姓名必须唯一

Also: Validate. 另外:验证。 Validate. 验证。 Validate . 验证

Quotes around attribute values are optional sometimes. 属性值周围的引号有时是可选的。 This isn't one of those times. 这不是那些时候之一。

我认为您必须在链接中添加target="_blank"属性。

In the window.open function, the second argument is the window's name. window.open函数中,第二个参数是窗口的名称。 Using the same name twice will load the new URL in the already-opened window. 两次使用相同的名称将在已打开的窗口中加载新的URL。 Just change the name in the function call (eg include the ID). 只需在函数调用中更改名称(例如,包括ID)。

You just need to make all popup window name different, otherwise last last one will just overwrite the previous one. 您只需要使所有弹出窗口的名称不同,否则最后一个倒数只会覆盖前一个。

 function openWindow(url)   
{
var width = 700;
var height = 500;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var windowFeatures = "width=" + width + ",height=" + height + " 
,status,resizable=no,scrollbars,left=" + left + ",top=" + top + "screenX=" + left + 
",screenY=" + top;
myWindow = window.open(url, "welcome", windowFeatures);
myWindow = window.open(url, "welcome2", windowFeatures);
myWindow = window.open(url, "welcome3", windowFeatures);// notice all popup window name is different
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM