Forum Moderators: open

Message Too Old, No Replies

Only One Popup Allowed?

         

Emperor

6:22 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



Hi guys,

I use this function to open a popup:

function openPopup(url,width,height)
{
window.open(url,"Game","width="+width+",height="+height+",status=no,menubar=no,toolbar=no,scrollbars=no,screenX=20,screenY=20,top=20,left=20,resizable=no");
}

And these links to execute:

<a href="javascript:openPopup('game01.htm','256','256');">Game 01</a>
<a href="javascript:openPopup('game02.htm','256','256');">Game 02</a>
<a href="javascript:openPopup('game03.htm','256','256');">Game 03</a>

...the thing is, I can only have one window open at a time. So if I click the first link (Game 01) it's fine, but when I click the second link it opens in the Game 01 window.

How do I make it so I can have multiple windows open?

Thanks.

bcolflesh

6:23 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You told it to open in the same named window = "Game".

Fotiman

6:55 pm on Oct 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Also, people with JavaScript disabled won't be able to access your games the way you've defined your links. Try this instead:

<a href="game01.htm" onclick="return openPopup(this.href,'256','256');">Game 01</a>

And change your openPopup method to return false.

Trace

6:55 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



Like mentionned above, you need to have different names to open new windows. You could easily modify what you already have;

function openPopup(url,winName,width,height)
{
window.open(url,winName,"width="+width+",height="+height+",status=no,menubar=no,toolbar=no,scrollbars=no,screenX=20,screenY=20,top=20,left=20,resizable=no");
}

<a href="javascript:openPopup('game01.htm','window1','256','256');">Game 01</a>
<a href="javascript:openPopup('game02.htm','window2','256','256');">Game 02</a>
<a href="javascript:openPopup('game03.htm','window3','256','256');">Game 03</a>

Emperor

7:07 pm on Oct 10, 2007 (gmt 0)

10+ Year Member



Ahhh, I see now. Thanks a lot guys.

rocknbil

2:50 am on Oct 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Better yet, just use the time function to ID the window.

function openPopup(url,width,height) {
var day = new Date();
var id = day.getTime();
window.open(url,id,"width="+width+",height="+height+",screenX=20,screenY=20,top=20,left=20);
return false;
}

<a href="game1.htm" onClick="return openPopup('game01.htm','256','256');">Game 01</a>
<a href="game2.htm" onClick="return openPopup('game02.htm','256','256');">Game 02</a>
<a href="game3.htm" onClick="return openPopup('game03.htm','256','256');">Game 03</a>

Note I've removed all the "no" 's - you don't need to specify no if you don't want an attribute. You only need to specify it if you want it.