[thelist] JavaScript problem with Netscape 4.7

Chris Nott cnott at telus.net
Fri Jan 16 21:01:12 CST 2004


> The following JavaS will prevent the page's content field from becoming
too
> wide on high resolution displays.
>
> /* Restrict growth of element on very-wide displays   */
>
> function resizeBox(){
>  sObj = document.getElementById("container")
>  if ( sObj ) {
>   if(document.body.clientWidth) (document.body.clientWidth>1024) ?
> sObj.style.width = "955px" :  sObj.style.width = "100%"
>  }
> }
>
>   window.onload = resizeBox;
>   window.onresize = resizeBox;
>
> --------------------------------------
>
>
> Works great in IE, NS, but not NS 4.7.

There's a couple reasons.
1. NS4.x doesn't support document.getElementById() to retrieve DOM
references to elements.  In fact, NS4.x is very limited in the types of
elements you can get any reference to.  You can use the DOM0 collections
(document.images[], document.links[], etc) or it's proprietary
document.layers[] collection which contains references to any layer
elements, or to div or span elements with position: absolute.  You can't get
a reference to a table element in NS4.x at all.
2. As mentioned by someone else, the width of the NS4.x browser window is
stored in window.innerWidth not document.body.clientWidth.  You could do an
object detection to see what property to use.
3.  NS4.x doesn't create a style object for any HTML elements.  You can set
the width (and a couple other properties) for objects in the
document.layers[] collection using: document.layers['myObjectId'].width =
'955';  You can only set dimensions in pixels and you have to leave the 'px'
off.

Unless you make major changes to your HTML, you aren't going to get this to
work in NS4.x.  Instead, you can leave your HTML as is and use Javascript
Style Sheets to change style values before the page begins to render in
NS4.x (the following code should go after any stylesheets and after the
above existing code):

if (document.ids && document.ids.container) {
   document.ids.container.width = (window.innerWidth >1024) ? '955px' :
'100%';
   window.onload = function() {}
   originalWindowWidth = innerWidth;
   originalWindowHeight = innerHeight;
   window.onresize = function() { if(innerWidth != originalWindowWidth ||
innerHeight != originalWindowHeight) location.reload(); };
}

- chris



More information about the thelist mailing list