# Javascript not working in IE, does anyone know why?

**URL:** <https://forum.kirupa.com/t/javascript-not-working-in-ie-does-anyone-know-why/233859>\
**Category:** web dev\
**Created:** [July 27, 2007, 3:12pm UTC](https://forum.kirupa.com/t/javascript-not-working-in-ie-does-anyone-know-why/233859 "2007-07-27T15:12:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fr\_ode](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@fr\_ode](https://forum.kirupa.com/u/fr_ode)\
**Post date:** [July 27, 2007, 3:12pm UTC](https://forum.kirupa.com/t/javascript-not-working-in-ie-does-anyone-know-why/233859/1 "2007-07-27T15:12:42Z")

</div>

I’m building a site with a background image that fills the browser viewport. It’s working great in Mozilla and Safari, but IE doesn’t work at all, and I have no idea why. Any ideas?

Here’s my HTML containing the Javascript…  
\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”  
“[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)”\>

```auto
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Resize</title>
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    </head>

<body onLoad="resize()" onResize="resize()">

<script language="JavaScript1.2">
    function resize() {        
        bg=document.getElementById("bg");
        cut=document.getElementById("bg_cut");    
        ratio = bg.offsetWidth/bg.offsetHeight;
        
        bg.style.position = 'absolute';
        bg.style.width = cut.offsetWidth + 'px';
        bg.style.height = '';
        bg.style.left = 0 + 'px';
        bg.style.top = Math.round((cut.offsetHeight - bg.offsetHeight))/2 + 'px';
        
        if(bg.offsetTop > 0) {
            bg.style.height = cut.offsetHeight + 'px';
            bg.style.width = '';
            bg.style.left = Math.round((cut.offsetWidth - bg.offsetWidth))/2 + 'px';
            bg.style.top = 0 + 'px';
        }        
    }
</script>

<div id="bg_cut">
    <img id="bg" src="img/background.jpg" alt="">
</div>

</body>
</html>

```

… and here’s the CSS.

```auto

html, body {
    width: 100%;
    height: 100%;
    margin: 0px;
    padding: 0px;
}

/* cutting the backround to fit the browser to avoid unwanted scrollbars */

#bg_cut {
    z-index: 1;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

```
