SitePoint Sponsor

User Tag List

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

    Re-Write a Layer's Content with Javascript

    These comments are in regards to the 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:
    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 ]
    [ | | ]

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Dallas, TX
    0 Post(s)
    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


Posting Permissions

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