View Full Version : How to restrict opening multiple windows by using window name

09-28-2008, 03:47 PM
Hi all,

I am new to this forums.I have requirement .In my Application I have so many links (urls) are there.If I am clicking on on link one new window is opening.for that i am using window.open(url,"windowname","');.If I am click the some link i am checking for the link is allready opend are not .if allready opend then i am setting the focus to the same window .this is working fine.
But instead of giving window name in window.open method we are mainting window name through the application .My problem is when I am clicking the another link(url) if it contains the same window name then it should give an alert and it should not give access to open a new window.please helpout to resolve this problem.

Thanks in advance


09-28-2008, 09:00 PM
You can play with this:

var winPop = null;
function openWindow(){
if(winPop && !winPop.closed){
alert("Pop Up is Open");
winPop = window.open(.......);


rnd me
09-29-2008, 05:17 AM
you can avoid a global variable like this : (im bored)

function openWin(url){
openWin.pu= openWin.pu || window.open("");
openWin.pu.location.href= url;
return openWin.pu;

the popup's window object would then be located at openWin.pu, as well as any variable set by calling openWin.

popupwin = openWin("blah");

09-29-2008, 07:02 AM
Hi Thanks for your replay.I am able to open windows and restricting ..

BUt my requirement is Two different urls with having same windowname then if I opend one window with windowname xyz and url like "http://localhost/one.html After that I am opening another window
with windowname xyz and url like "http://localhost/two.html
then it should give alert like a window is allredy opend eith this window name..
I hope you got my point and waiting for your replay


rnd me
09-29-2008, 08:10 AM
i see.

function openWin(url){
openWin.pu= openWin.pu || window.open(url);
if( openWin.url && (url !== openWin.url) ){ return alert("Page in Use!"); }
openWin.url = url;
return openWin.pu;