Click to See Complete Forum and Search --> : onload, open new window, centered on screen


caynada
02-05-2003, 07:37 AM
I would like to have an onload comand that would open a new window (with specific size and properties) centered on the screen. I've done it with a button before, but can't seem to make it work with the "onload". Any ideas?

pyro
02-05-2003, 07:39 AM
Why not post you code? If it works with a button, it should be no problem to get it to work onLoad.

caynada
02-05-2003, 07:45 AM
On a button in Flash I had this:

on (release) {
getURL("JavaScript:new_win('caribbean_map.html', '436', '372');");
}

Then in the html doc. I had this:

<script language="JavaScript" type="text/JavaScript">
function new_win(new_page, win_width, win_height) {
var posLeft= ((screen.width/2)-(win_width/2));
var posTop= ((screen.height/2)-(win_height/2));

winID= window.open(new_page, 'newWin', 'toolbar=no, location=no, scrollbars=yes, resizable=yes, width=' + win_width + ', height=' + win_height + ', left=' + posLeft + ', top= ' + posTop);
winID.focus();
}

</script>

What I would like to happen is when this specific html page opens it automatically opens a new window in the center.

pyro
02-05-2003, 07:49 AM
Try this. <body onLoad="new_win('caribbean_map.html', '436', '372');">

caynada
02-05-2003, 07:53 AM
I tried putting that in the first html doc. in the body tag, but it didn't work. Is this the right place?

pyro
02-05-2003, 08:02 AM
This code works fine for me.

<html>
<head>

<script language="JavaScript" type="text/JavaScript">
function new_win(new_page, win_width, win_height) {
var posLeft= ((screen.width/2)-(win_width/2));
var posTop= ((screen.height/2)-(win_height/2));

winID= window.open(new_page, 'newWin', 'toolbar=no, location=no, scrollbars=yes, resizable=yes, width=' + win_width + ', height=' + win_height + ', left=' + posLeft + ', top= ' + posTop);
winID.focus();
}

</script>

</head>

<body onLoad="new_win('caribbean_map.html', '436', '372');">

</body>
</html>

caynada
02-05-2003, 08:10 AM
I went wrong by putting the onload command on the first page and then the script that dictates the page position on the second page.

I tried what you sent, it does open a new window but for some reason it is twice the specified width and in the upper right corner. Any ideas?

pyro
02-05-2003, 08:17 AM
Originally posted by caynada
I tried what you sent, it does open a new window but for some reason it is twice the specified width and in the upper right corner. Any ideas? No, not really. It is working fine for me in IE6, NN7, and Mozilla 1. What browser are you using?

caynada
02-05-2003, 01:28 PM
I'm using IE 5.2 on a Mac. Thanks a lot for all your help. For some reason I still couldn't get it to work properly. So I'm just going to have it open in the top left, which works fine.

Thanks again