开发者

Multiple popup windows using javascript

开发者 https://www.devze.com 2022-12-21 18:41 出处:网络
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

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

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


remove var myWindow from above the function and place it inside the function.


You create a window called "welcome" when you run the function for the first time. 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.


In the window.open function, the second argument is the window's name. Using the same name twice will load the new URL in the already-opened window. Just change the name in the function call (e.g. include the 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
} 


i think you have to add the target="_blank" attribute to your link.

0

精彩评论

暂无评论...
验证码 换一张
取 消