...

View Full Version : Open and center window function



Spidey1980
01-11-2012, 07:03 PM
100% working code for you to copy and paste:


function openWindow(the_url, the_size)
{
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2) - (the_size / 2);
var top_point = parseInt(screen_height / 2) - (the_size / 2);
var the_features = "width=" + the_size + ",height=" + the_size + ",top=" + top_point + ",left=" + left_point;
var the_window = window.open(the_url, "", the_features);
}


example use


<a href = "#" onClick =
"openWindow('http://www.http://bookofjavascript.com/', 500); return false;">Click me to open book of Java Script</a>



full example:


<html>
<head>
<title>Functions</title>
<script type = "text/javascript">
<!--
//open and center window function based on bookofjavascript.com by thau!
//modified by Spidey1980 for reusability
function openWindow(the_url, the_size)
{
var screen_height = window.screen.availHeight;
var screen_width = window.screen.availWidth;
var left_point = parseInt(screen_width / 2) - (the_size / 2);
var top_point = parseInt(screen_height / 2) - (the_size / 2);
var the_features = "width=" + the_size + ",height=" + the_size + ",top=" + top_point + ",left=" + left_point;
var the_window = window.open(the_url, "", the_features);
}
// -->
</script>
</head>
<body>
<a href = "#" onClick =
"openWindow('http://www.http://bookofjavascript.com/', 500); return false;">Click me to open book of Java Script</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum