/    Sign up×
Community /Pin to ProfileBookmark

onload, open new window, centered on screen

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?

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — Why not post you code? If it works with a button, it should be no problem to get it to work onLoad.
Copy linkTweet thisAlerts:
@caynadaauthorFeb 05.2003 — 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.
Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — Try this. <body onLoad="new_win('caribbean_map.html', '436', '372');">
Copy linkTweet thisAlerts:
@caynadaauthorFeb 05.2003 — I tried putting that in the first html doc. in the body tag, but it didn't work. Is this the right place?
Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — This code works fine for me.

&lt;html&gt;
&lt;head&gt;

&lt;script language="JavaScript" type="text/JavaScript"&gt;
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();
}

&lt;/script&gt;

&lt;/head&gt;

&lt;body onLoad="new_win('caribbean_map.html', '436', '372');"&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@caynadaauthorFeb 05.2003 — 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?
Copy linkTweet thisAlerts:
@pyroFeb 05.2003 — [i]Originally posted by caynada [/i]

[B]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? [/B][/QUOTE]
No, not really. It is working fine for me in IE6, NN7, and Mozilla 1. What browser are you using?
Copy linkTweet thisAlerts:
@caynadaauthorFeb 05.2003 — 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
×

Success!

Help @caynada spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...