PDA

View Full Version : Take a quick look at my pop-up syntax ?


mat
09-30-2002, 09:34 PM
Would someone mind taking a look over my code, it works but there is probably a mistake somewhere or the wrong syntax etc, myabe i have something that doesn't need to be there etc,


function openWindow(url, x, y)
{
var options = "toolbar=no,menubar=no,scrollbars=no,resizable=no,width="+x+",height="+y;
pWindow = window.open(url, "openWindow", options);
}

..then later on down the page:


<td><A HREF='file' target='popup' onClick="javascript:openWindow('detail.php?pot=45','popup','400', '430'); return false">


mat,

mordred
09-30-2002, 10:14 PM
I see an unnecessary line break in the window options string, but that looks like coming from the browser/forum software. Anyway, I would change the link to


<a href='detail.php?pot=45' target='popup' onclick="openWindow('detail.php?pot=45','400', '430'); return false">


You do only use the "javascript:" pseudo-protocol when you call the javascript statement from within the href attribute. Everything inside an eventhandler is considered to be JS, so you actually don't need it there. I also put the popup URL into the href, so that this link degrades painlessly for users who have JS disabled (it should just open a new window). Last but not least, I removed one argument of openWindow(), because you expect only three, not four, and you defined the window's name in the function itself.

beetle
10-01-2002, 01:32 AM
Mordred, I'd probably go one more step<a href='detail.php?pot=45' target='popup' onclick="openWindow(this.href,'400', '430'); return false"> That makes maintenance easier....

glenngv
10-01-2002, 08:08 AM
you have different number of arguments for the function

maybe you wanted it like this:

function openWindow(url, target, x, y)
{
var options = " toolbar=no,menubar=no,scrollbars=no,resizable=no,width="+x+",height="+y;
pWindow = window.open(url, target, options);
}

<a href='detail.php?pot=45' target='popup' onclick="openWindow(this.href,this.target,'400', '430'); return false">