Question subject: invalid argument on IE with script to center objects
Posted: Tue Sep 21, 2010 9:12 am
Joined: Tue Sep 21, 2010 9:03 am Posts: 1 Has thanked: 0 time Have thanks: 0 time
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;