Problem with getting the doc

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

    #1

    Problem with getting the doc

    Hello,

    I use the following javascript code, which works well in IE and Opera,
    but doesn't work with Firefox and Mozilla.

    I always get an error "doc is not defined" when try to run code
    eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))

    Before I setup the doc variable as this:
    var ie = document.all ? 1 : 0
    var ns = document.layers ? 1 : 0
    if(ns){doc = "document." ; sty = ""}
    if(ie){doc = "document.all." ; sty = ".style"}

    Any idea?

    Thanks!
  • Randy Webb

    #2
    Re: Problem with getting the doc

    Clemenza wrote:[color=blue]
    > Hello,
    >
    > I use the following javascript code, which works well in IE and Opera,
    > but doesn't work with Firefox and Mozilla.[/color]

    It doesn't "work well" in IE or Opera, you just think it does.
    [color=blue]
    > I always get an error "doc is not defined" when try to run code
    > eval(doc + layerName + sty + ".left = " + (eval(FromLeft) + 15))[/color]

    Why are you using eval when you don't need it?
    Had you bothered reading the group FAQ before posting you would have,
    undoubtedly, found this section:



    [color=blue]
    > Before I setup the doc variable as this:
    > var ie = document.all ? 1 : 0
    > var ns = document.layers ? 1 : 0
    > if(ns){doc = "document." ; sty = ""}
    > if(ie){doc = "document.all." ; sty = ".style"}[/color]

    Geeeez....
    Ummm, you should read that FAQ, especially section:


    [color=blue]
    > Any idea?[/color]

    Trash your code, buy a book, and start over.
    [color=blue]
    > Thanks![/color]

    Welcome.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

    Comment

    • David Dorward

      #3
      Re: Problem with getting the doc

      Clemenza wrote:
      [color=blue]
      > I use the following javascript code, which works well in IE and Opera,
      > but doesn't work with Firefox and Mozilla.[/color]
      [color=blue]
      > var ie = document.all ? 1 : 0[/color]

      Internet Explorer stuff that Opera and Mozilla support - but Mozilla only
      very recently introduced support and returns false to document.all to
      discourage its use. You only need this if you need to support versions of
      IE older then 6.
      [color=blue]
      > var ns = document.layers ? 1 : 0[/color]

      Netscape 4 specific code. Support dropped after the 4.x series.

      See http://www.mozilla.org/docs/web-deve...upgrade_2.html

      --
      David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
      Home is where the ~/.bashrc is

      Comment

      Working...