Reputation: 101
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
Upvotes: 0
Views: 686
Reputation: 788
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
}
Upvotes: 0
Reputation: 944565
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.
Upvotes: 1
Reputation: 39208
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).
Upvotes: 0
Reputation: 4267
remove var myWindow from above the function and place it inside the function.
Upvotes: 1
Reputation: 8461
i think you have to add the target="_blank"
attribute to your link.
Upvotes: -1