justuptime.com - monitor your servers & websites

Forcing new windows to be a certain size and position

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.
mfdc's picture

They have: 166 posts

Joined: Aug 2004

Im going to try and post this, and hopefully someone will be able to help. I really dont know what im doing wrong with my posts, and apologies if I am but no one seems to answer them.

I have a website with several links and when each new window opens I would like to be able to force not only the size of the Window but to center it too!?

Could someone offer some greatley appreciated advice!

Megan's picture
Administrator

She has: 10,030 posts

Joined: Jun 1999

Sorry you're not getting answers to your questions! I'll take a look and see if there are any I can help with.

Are you using target_blank of a javascript pop-up to open the window? To resize a new window you'll have to use JavaScript. Here is a tutorial:

http://www.pageresource.com/jscript/jwinopen.htm

You won't be able to centre the window - only position it from the top-left corner (that's explained at the bottom of that page).

mfdc's picture

They have: 166 posts

Joined: Aug 2004

Bless you, thats delightful

Thanks

teammatt3's picture
Moderator

He has: 1,831 posts

Joined: Sep 2003

Quote: You won't be able to centre the window - only position it from the top-left corner (that's explained at the bottom of that page).

Couldn't you get the size of the monitor using screen.width and screen.height and since you have the size of the browser window, you could do some math to figure out how far from the top and left would make the browser center? I haven't done it, but it might work. IE, Opera and Firefox probably have different opinions on what constitutes the browser window, so your centering might be a bit off.

Megan's picture
Administrator

She has: 10,030 posts

Joined: Jun 1999

webwiz wrote: Anyone have a solution to these issues?

Um, don't use pop-up windows? Almost always a bad idea but mfdc didn't ask about that Wink Maybe he's got a good reason for it.

teammatt3;224028 wrote: Couldn't you get the size of the monitor using screen.width and screen.height and since you have the size of the browser window, you could do some math to figure out how far from the top and left would make the browser center? I haven't done it, but it might work. IE, Opera and Firefox probably have different opinions on what constitutes the browser window, so your centering might be a bit off.

Oh, right you could do it that way. You'd also have to do some math to get what the x,y position of the top-left corenr of the window would be relative to the center of the screen. But who would go to that much trouble just to center a pop-up?

mfdc's picture

They have: 166 posts

Joined: Aug 2004

The windows that open must have navigation via scrollbars hence regular windows would of been fine, pop ups a no no!

He has: 301 posts

Joined: May 2007

I hesitate doing something like this, as I don't know how to do it unobtrusively.

Modern browsers allow you to stop JavaScript from resizing and moving windows. In addition, most pop-up blockers will not open a new window without permission. This adds a barrier to visitors that may well put them off. It also raises usability issues.

Anyone have a solution to these issues?

Cordially, David
--
"Old web developers don't die, they degrade gracefully..."