self centering window?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

There is probably a simple way to make a window open in the center of
the screen.... javascript?

Just how?

Re: self centering window?

Sonnich wrote:
Quoted text here. Click to load it

There use to be, but most modern browsers will not let you have such
control. Your control is limited within the chrome...

Take care,


Re: self centering window?

Jonathan N. Little skrev:

Quoted text here. Click to load it

Most browsers will let you do that, but with som limitations.

Re: self centering window?

Roy A. wrote:
Quoted text here. Click to load it

All browser dose support window placing and resizing, but it's quite usual
that users disables such things, myself I only allow javascript to open a new
window if I'm clicking on a link, but I don't allow any resizing or placement
for windows and always keep status bar visible.

IMHO javascript should be used sparsely and never count on that a user who
visit a page will have javascript enabled, and those times when using
javascript, don't use jscript mixed into it.



Re: self centering window?

You'll want to align everything to the left and top, flush, so your
page is all ready to go, and then insert that page into a new one using
an iframe..

good luck!!

Re: self centering window?

In article wrote:

Quoted text here. Click to load it

Please quote what you are replying to. It does not naturally
appear for those of us not on Google.

Because of my incredibly unique memory, I can add:

Plus this does not get the OPs window into the middle of any
users screen.


Re: self centering window?

Sonnich skrev:
Quoted text here. Click to load it

Not with HTML. With JavaScript you could read the screen resolution
with the screen object found in most browsers, by using the
screen.width and screen.height methods.

With these values you could use the method to open a window
centered on the screen.

<script type="text/javascript">
  function open_centered_window() {
    var w = 400; var x = (screen.width - w) / 2
    var h = 300; var y = (screen.height - h) / 2"/index.html","_blank","toolbar=yes,location=yes,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=no,copyhistory=yes,width="+w+",height="+h+",left="
+ x + ", top="+y)
<a href="/index.html" onclick="open_centered_window();return
false">open window in the center of the screen</a>

This is working in most browsers, but the user can deside to block
pop-up windows, or it can be blocked bye e.g. a proxy. Browsers want to
give the user full control, and will block windows that isn't result on
a event trigged by the user.

Re: self centering window?

Sonnich skrev:
Quoted text here. Click to load it

Insted of opening the window in the center of the screen, you should
proberly center it acording to the "parent window". A user may have two
monitors, so the center of the screen may mean "between" two windows.
You should also check if the browser have a window and a screen object.

Site Timeline