PDA

View Full Version : [Javascript] Small bug somewhere



Wojtek
February 20th, 2004, 12:45
The javascript code:


<script language=Javascript>
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,
statusbar=0,menubar=0,resizable=0,width=300,height=500,
left=((screen.width/2)-150),top=((screen.height/2)-250)');");
}
</script>

What I've done here is replaced fixed size values for left and top wich I used on my 1024x768 resolution to make the pop centered. However, when I did the screen/2 method, it pops in the upper left corner, not centered.

Any ideas why?

Thanks :)

DBers
February 20th, 2004, 22:52
I'm not that into JavaScript as of late. but this works for me:

[code]
<script language=Javascript>
function popUp(URL)
{
day = new Date();
id = day.getTime();
w = 300;
h = 500;
l = (screen.width/2) - (w/2);
t = (screen.height/2) - (h/2);
window.open(URL,id,"toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resi zable=0,width=" + w + ",height="+ h + ",left=" + l + "top="+ t);
}
</script>
[code]

Wojtek
February 21st, 2004, 00:21
that code gives me a javascript error

DBers
February 21st, 2004, 00:53
when you copy and paste, make sure that there are no breaks in the window function.

goto resiza and press delete, pring the line below it up

for some reason the boards ads a break line at the end of each line when posting

Wojtek
February 21st, 2004, 01:02
Excellent

Works perfectly!

Thanks :)