Switch to full style
HTML,DHTML,Javascript,XML,CSS
Post a reply

invalid argument on IE with script to center objects

Tue Sep 21, 2010 9:12 am

Hi there! First time posting here! I hope you can help me.
I have a problem with a script I made to center horizontally and vertically an object with an id of "centered". This code works onLoad and every time the screen is resized. This works perfectly fine on firefox, chrome, and safari. For some reason I cannot understand why it doesn't work on IE. I get an error about an invalid argument on line 18, which is where I calculate the final position. here is the code:
any help would be greatly appreciated!

Code:
<html>
<head>
   
<script>
   
window.onresize = center;


function center(){

    var objwidth = document.getElementById('centered').offsetWidth;
    var objheight = document.getElementById('centered').offsetHeight;
    var screen_height = window.innerHeight;
    var screen_width = window.innerWidth;
    var centx = (screen_width/2) - (objwidth/2);
    var centy = (screen_height/2) - (objheight/2);
    document.getElementById('centered').style.position = "absolute";
    document.getElementById('centered').style.top = centy;
    document.getElementById('centered').style.left = centx;
   
}

</script>


</head>
<body onLoad="center();">
   
<table  border="1" id="centered" height="250" width="375">
    <tr><td>1</td><td>2</td></tr>
    <tr><td>3</td><td>4</td></tr>
</table>


   
   
   
</body>
</html>




Post a reply
  Related Posts  to : invalid argument on IE with script to center objects
 Invalid Argument error in IE7     -  
 Using Web Objects in XML (WOX) to serialize Java objects XML     -  
 Center logo     -  
 invalid drive or directory     -  
 Invalid integer formats     -  
 Bounding Box to Center Text by php     -  
 Passing an Argument to a Function by Value     -  
 Function with an Optional Argument     -  
 Move content to center of the page     -  
 argument type of a program's main() method     -