Forum Moderators: open

Message Too Old, No Replies

Getting Window Size(width)

Strange Problem in IE, incorrect value returned

         

Birdman

5:21 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm working on a basic(I thought) script that will display some content if the user's window is over 1000px wide.

My problem is that IE is displaying the incorrect width.

The strange part is, if I place this function on a different webpage, the value is suddenly correct. I am implementing the code in my global header include file.

Here's the function:


<script type="text/javascript">
function wid(){
winW = 0;
if (parseInt(navigator.appVersion)>3) {
if (navigator.appName=="Netscape") {
winW = window.innerWidth-16;
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
winW = document.body.offsetWidth-20;
}
}
alert(winW); //debug
if(winW > 1000){
ad = "HTML code here";
document.body.innerHTML += ad;
}

}

window.onload = wid;
</script>

When used in the global header file, the script outputs 984. In another page, with no header include, it outputs 1004 as expected.

Any ideas? I suspect it's some error in my HTML, yet I can't find it.

Birdman

7:29 pm on Aug 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it, thanks to DrDoc.

[webmasterworld.com...]