SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast morgion's Avatar
    Join Date
    Jun 2002
    Location
    Fargo, ND
    Posts
    54
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re-Write a Layer's Content with Javascript

    These comments are in regards to the SitePoint.com article 'Re-Write a Layer's Content with Javascript'.

    I've recently read an article by Code"NiceLady" *cough* over at MacEdition, entitled Exhausted by sniffing. A little ranty, but it has a lot of good points.

    In the section "Do it right and ELSE", she points out a pitfall of sniffing; user agent spoofing (e.g., iCab pretends to be NS4.x). Solution: make sure your scripts evaluate browsers by their capabilities (document.layers, document.all, document.getElementById), then don't assume support of one capability means support of another feature.

    That being said, take a look at the following code:
    Code:
    else if (parseInt(navigator.appVersion)>=5&&navigator.
    appName=="Netscape") {
    document.getElementById(ID).innerHTML = sText;
    }
    Is the version and app name check neccessary, or would "else if (document.getElementById)" be better?
    Lord Morgion
    Paranoia is just reality on a finer scale. - Strange Days
    [ MacOS X | Mozilla | 1280 x 854 (15" PowerBook G4) | Millions ]
    [ www.ambientshadow.com | www.gerbilmechs.com | www.gogeek.org ]

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Definitely better to check for object/property support first. There are RARE occasions where browser detection by name/version is the only way to achieve a certain result.

    For example, IE 5 has problems with certain regular expression patterns. IE 4, 5.5, and 6 don't. There's no object detection to directly detect this. Yes, I could probably combine some object tests to pinpoint IE5, but in this case, accessing the navigator object is preferable.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •