views:

57

answers:

4

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

A: 

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

j.
No, you don't. This is JavaScript.
David Dorward
hmm. right. tks
j.
+1  A: 

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

Salvin Francis
+1  A: 

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.

David Dorward
A: 

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).

streetpc