Forum Moderators: open

Message Too Old, No Replies

Popup Window Woes

It works the first time, but not the second

         

jdkuehne

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

10+ Year Member



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;
}[/size]

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>
<br>
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]

Fotiman

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

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



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

jdkuehne

4:09 pm on Mar 9, 2010 (gmt 0)

10+ Year Member



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.