Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Popup Window Woes

It works the first time, but not the second

3:00 pm on Mar 9, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 11, 2005
posts: 76
votes: 0

I'm using the follow snippet of code in a page to create a new, sized window when the user clicks on a link. There are two instances, one right after the other. The first instance brings up a properly sized window. The second instance opens a full size window. The behavior is the same in both IE and FF.

In a separate file - mywin.js:

[size=2]function myWin (url,w,h) {
var day = new Date();
var id = day.getTime();
var wid = w+20;
var ht = h+20;
var params = 'width='+wid+',height='+ht+',scrollbars,resizable';
var win = open(url,id,params);
return false;

Code in the header:

[size=2]<script type="text/javascript" src="http://www.example.com/mywin.js"></script>[/size]

Code in the body:

[size=2]click <a href="../page1.html" onclick="return myWin('../page1.html',560,600);">here</a>
click <a href="../page2.html" onclick="return myWin('../page2.html',560,600);">here</a>[/size]

Can anyone explain what's happening? Thanks.

[edited by: Fotiman at 3:44 pm (utc) on Mar 9, 2010]
[edit reason] Examplified URL [/edit]

3:44 pm on Mar 9, 2010 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
votes: 26

It works for me as expected. You might try adding an alert statement just before the open, like:

alert("About to open window '" + id + "' with params: " + params);

The only thing I can think of would be that perhaps your code has a typo in your onclick attribute.

Also, you can simplify your code slightly by doing this:

<a href="../page1.html" onclick="return myWin(this.href,560,600);">here</a>

That way, you don't have to duplicate the URL (which would increase the chances of error).
4:09 pm on Mar 9, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 11, 2005
posts: 76
votes: 0

Thanks Fotiman,

There were no typos, so all I can think is that something in the .net code that the snippet is part of was causing the problem. At any rate, your modification did the trick. Thanks for the quick reply.