/    Sign up×
Community /Pin to ProfileBookmark

specified window size and centered on user screen

I’m trying to launch a browser window at a specified size and have it center itself on the user’s screen. The size issue I’m dealing with by having my index page onLoad launch a new window at a set size containing the home page. (If there’s a better way to deal with that I’d love to know it) What I want to happen after that is to have that new window center itself, and if possible close the original window (the end I’m looking for here is only one window open, centered on screen)

I’ve found a couple tutorials that expand and center, or that launch a new window after clicking a link and center that window—but none that I’ve been able to get to work for my specific need here.

Any help?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@crh3675Feb 09.2004 — You can't force the closing of the parent window if it is the original browser window opened. I don't think you can accomplish what you are looking to do.

Let me guess, you want the size of the the window to change with the content inside?

You can put a DIV around all of your content and then put this onload event in your page:

<i>
</i>&lt;html&gt;
&lt;script&gt;
function init()
{
var bodyDiv=document.getElementById("yourdiv");
var x=bodyDiv.offsetWidth+42;
var y=bodyDiv.offsetHeight+58;
window.resizeTo(x,y);
window.moveTo(screen.height/2-bodyDiv.offsetWidth/2,screen.height/2-bodyDiv.offsetHeight/2);
}
&lt;/script&gt;

&lt;body onload="init()"&gt;
&lt;div id="yourdiv" style="width:500px"&gt;
this is my content
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@blackhorseauthorFeb 10.2004 — If I don't need the window to change size w/ my content (it's an .swf movie, all the same size) just to stay a specific size and centered, how does that change the script?

Thanks for your reply.
Copy linkTweet thisAlerts:
@rhsundergroundFeb 10.2004 — i don't know about centering the window, but to close the original do something like this :
[code=php]<script>
function switchUp() {
window.open('whatever.html','whatever','width=, height=')
window.close(self)
}
</script>

[/code]
Copy linkTweet thisAlerts:
@blackhorseauthorFeb 10.2004 — Thanks. The window.close(self) did the trick.

Any idea if the file I'm loading in the new window is relative, is there a problem with browsers with pop-up blockers (i.e. will they block the display of my new window which will essentially contain my entire site)
Copy linkTweet thisAlerts:
@KorFeb 10.2004 — ...in this case maybe it would have been a better ideea to use inline/none displayed layers instead of pop-ups...
Copy linkTweet thisAlerts:
@rhsundergroundFeb 10.2004 — many pop-up blockers will filter out this main page that you're trying to open. but luckily for you, many won't. I recommend that on your main page, you have a script calling to open the new window. put on the page a button or link that will open the page if it didn't open otherwise and one that will close the current window. will post back with a possibilty of how to set the window height and width once i find my info.


until next time...
×

Success!

Help @blackhorse 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,
)...