Window sizes NN6.x or higher

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jochen Califice

    Window sizes NN6.x or higher

    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.layer s)
    {
    sw = innerWidth;
    sh = innerHeight;
    }
    else
    {
    sw = document.body.o ffsetWidth;
    sh = document.body.o ffsetHeight;
    }

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

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

    if (document.getEl ementByID)
    {
    var ide=document.ge tElementById("a ktuell");
    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


  • Lasse Reichstein Nielsen

    #2
    Re: Window sizes NN6.x or higher

    "Jochen Califice" <mail@boomboxx. de> writes:
    [color=blue]
    > function Aufloesung()
    > {
    >
    > if (document.layer s)
    > {
    > sw = innerWidth;
    > sh = innerHeight;[/color]


    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.innerWid th == "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.
    [color=blue]
    > }
    > else
    > {
    > sw = document.body.o ffsetWidth;[/color]

    you might mean
    document.body.c lientWidth
    It is more relevant for height, since the body might not take up the
    entire viewport.

    In some cases it should be
    document.docume ntElement.clien tWidth

    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 - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Martin Honnen

      #3
      Re: Window sizes NN6.x or higher



      Jochen Califice wrote:[color=blue]
      > 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.layer s)
      > {
      > sw = innerWidth;
      > sh = innerHeight;
      > }
      > else
      > {
      > sw = document.body.o ffsetWidth;
      > sh = document.body.o ffsetHeight;
      > }[/color]

      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.innerWid th != 'undefined') {
      width = window.innerWid th;
      height = window.innerHei ght;
      }
      That way you have width and height for all browsers implementing
      window.innerWid th (which are at least Netscape 4, Netscape 6/7 and all
      Mozilla based browsers.)

      --

      Martin Honnen


      Comment

      Working...