Window sizes NN6.x or higher

Discussion in 'Javascript' started by Jochen Califice, Jun 29, 2003.

  1. Hi NG!

    A wise man said "You don't have to know anything but where to find it" :)
    K I've been searching about two hours but didn't find one thing usable.

    I have a layer at my page. In it there's a picture. I want this layer always
    to be placed at the middle of the screen.
    So I read out the window width and replace the layer. Works fine.

    The problem is, that I don't know how to read out window width using NN6.x
    or higher. Heres my function:

    --------------------------------------------------------------

    function Aufloesung()
    {

    if (document.layers)
    {
    sw = innerWidth;
    sh = innerHeight;
    }
    else
    {
    sw = document.body.offsetWidth;
    sh = document.body.offsetHeight;
    }

    if (document.all)
    {
    ide=document.all["aktuell"];
    abstand=(sw-332)/2;
    ide.style.left=abstand;
    }

    if (document.layers)
    {
    document.layers["aktuell"].pageX=(sw-332)/2;
    }

    if (document.getElementByID)
    {
    var ide=document.getElementById("aktuell");
    ide.style.left=(sw-332)/2;
    }

    }

    --------------------------------------------------------

    IE and NN4.x works fine. But no chance for NN6.x or higher :(
    Could some one help me, please? The problem is about to drive me mad :)

    Thanx a lot! ...Jochen
     
    Jochen Califice, Jun 29, 2003
    #1
    1. Advertisements


  2. Why only use innerWidth in Netscape 4? Instead of testing for
    document.layers (which has nothing to do with innerWidth)
    you could test for innerWidth directly:

    if (typeof window.innerWidth == "number")

    (the prefixed window is important. An undefined variable is an error,
    an undefined property has the value "undefined").

    You will find that Mozilla (and derivatives like Netscape 6+)
    understands innerWidth and innerHeight.
    you might mean
    document.body.clientWidth
    It is more relevant for height, since the body might not take up the
    entire viewport.

    In some cases it should be
    document.documentElement.clientWidth

    See <ULR:http://jibbering.com/faq/#FAQ4_9>


    You can also center horizontally using CSS:

    body {text-align:center; /* because IE5 sucks */}
    div {
    width:332px;
    margin:0px auto;
    text-align:left;
    }

    /L
     
    Lasse Reichstein Nielsen, Jun 29, 2003
    #2
    1. Advertisements

  3. This is the wrong approach, if you check for document.layers then you
    can assume Netscape 4, but as your aim is to find the the window
    dimensions you should check for the properties
    var width, height;
    if (typeof window.innerWidth != 'undefined') {
    width = window.innerWidth;
    height = window.innerHeight;
    }
    That way you have width and height for all browsers implementing
    window.innerWidth (which are at least Netscape 4, Netscape 6/7 and all
    Mozilla based browsers.)
     
    Martin Honnen, Jun 29, 2003
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.