|
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]
|