PDA

View Full Version : resize and center window?



peejeno
11-05-2006, 05:38 PM
hey guys, im looking for a script that can resize the window its in, like this


<script language="JavaScript">
<!--
function resize_400x300()
{
window.resizeTo(400,300)
}
-->
</script>


with any size, but i would also like that window to be centered? :confused: Is it possible?
any help would be much helpfull!;)
thanks.

-peej

DimX
11-05-2006, 07:33 PM
function resizeAndCenter(width, height) {
window.resizeTo(width, height);
window.moveTo((screen.availWidth-width)/2, (screen.availHeight-height)/2);
}

resizeAndCenter(400, 300);

mburt
11-05-2006, 08:11 PM
If screen.availWidth-width is an odd number, when you divide it by two, wouldn't that cause an error? (where it'll be a decimal)
eg: trying to set the screen left to 35.5

jscheuer1
11-05-2006, 10:35 PM
You are much better off devising a better way of designing your page so that such javascript dependant schemes are not required.

peejeno
11-06-2006, 04:48 AM
thanks DimX, works great! :) :) :)