DHTML / Styles in JavaScript...error msgs.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • A. Nonymous

    DHTML / Styles in JavaScript...error msgs.

    I am trying to write a function that will centre a DIV-layer into the middle of the web browser screen. This is only for Internet Explorer. I keep getting and Invalid Argument error whenever I call the function (in the line oRef.style.left = ...).

    I am brain dead! What's wrong with my code?

    TIA..

    function CentreOnScreen( LayerID)
    {
    var oRef = eval('document. all.'+ LayerID);
    //alert(oRef +', '+ LayerID);
    oRef.style.left = (screen.availWi dth - oRef.style.widt h)/2;
    oRef.style.righ t = (screen.availHe ight - oRef.style.heig ht)/2;
    oRef.style.zInd ex = 1;
    }
  • Martin Honnen

    #2
    Re: DHTML / Styles in JavaScript...er ror msgs.



    A. Nonymous wrote:

    [color=blue]
    > function CentreOnScreen( LayerID)
    > {
    > var oRef = eval('document. all.'+ LayerID);[/color]

    Make that
    var oRef = document.getEle mentById(LayerI D);
    if (oRef && oRef.style) {
    [color=blue]
    > oRef.style.left = (screen.availWi dth - oRef.style.widt h)/2;[/color]

    CSS properties are strings as for instance width is a number plus a unit
    so if you really want to use style.width then you need to call parseInt
    on it e.g.
    oRef.style.left =
    (screen.availWi dth - parseInt(oRef.s tyle.width)) / 2 + 'px';
    however I guess you want
    oRef.style.left =
    (screen.availWi dth - oRef.offsetWidt h) / 2 + 'px';
    [color=blue]
    > oRef.style.righ t = (screen.availHe ight - oRef.style.heig ht)/2;[/color]

    Same problems here.

    --

    Martin Honnen

    Comment

    • A. Nonymous

      #3
      Re: DHTML / Styles in JavaScript...er ror msgs.

      Okay,

      I think I figured it out!

      1) I need parseInt() around the expression (availHeight - height/2)

      2) There is no such attribute as obj.style.right . That should read obj.style.top.

      3) The DIV-layer I'm using needed style="position : absolute" in the tag.
      "A. Nonymous" <anonymous@hotm ail.com> wrote in message news:6M6dnVTPK5 lwjXHcRVn-gA@giganews.com ...
      I am trying to write a function that will centre a DIV-layer into the middle of the web browser screen. This is only for Internet Explorer. I keep getting and Invalid Argument error whenever I call the function (in the line oRef.style.left = ...).

      I am brain dead! What's wrong with my code?

      TIA..

      function CentreOnScreen( LayerID)
      {
      var oRef = eval('document. all.'+ LayerID);
      //alert(oRef +', '+ LayerID);
      oRef.style.left = (screen.availWi dth - oRef.style.widt h)/2;
      oRef.style.righ t = (screen.availHe ight - oRef.style.heig ht)/2;
      oRef.style.zInd ex = 1;
      }

      Comment

      Working...