You are here: Re: self centering window? « HTML « IT news, forums, messages
Re: self centering window?

Posted by Roy A. on 01/12/07 23:13

Sonnich skrev:
> Hi
>
> There is probably a simple way to make a window open in the center of
> the screen.... javascript?
>
> Just how?

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 window.open method to open a window
centered on the screen.

<html>
<head>
<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

window.open("/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)
}
</script>
</head>
<body>
<a href="/index.html" onclick="open_centered_window();return
false">open window in the center of the screen</a>
</body>
</html>

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация