Total members 11894 |It is currently Sun Nov 24, 2024 1:18 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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>





Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time
Post new topic Reply to topic  [ 1 post ] 

  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     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com