SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a full proof way of testing whether browser is IE or Mozilla?

    Hi All

    This post is related to a previous post. I am trying to position a popup window on the screen. I have ascertained that NS6+/Mozilla using 'window.screenX/screenY' property to position the window. IE5/6 uses 'window.left/top', right?

    Assuming the above assumptions are correct, I am trying to write a function that detects which object model is supported. However I just cant get it to work. I have been through all the DOM docs for Mozilla and IE, but still cant get it to work.

    Has anyone done this sort of thing before. If so could you please tell me how you did it?

    Many thanks,

    Ben
    Experience is that thing which lets you know you've made the same mistake yet again.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the most effective test I've found for detecting Netscape 6+ and Mozilla 1.0+:

    var ua = navigator.userAgent.toUpperCase();
    if (ua.indexOf('GECKO') != -1){

    /* put your pop up script here */

    }

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by shoop
    This is the most effective test I've found for detecting Netscape 6+ and Mozilla 1.0+:

    var ua = navigator.userAgent.toUpperCase();
    if (ua.indexOf('GECKO') != -1){

    /* put your pop up script here */

    }
    Watch out! You may inadvertently get Safari (http://www.apple.com/safari/) and Opera (http://www.opera.com/) with this check! Here's a modified one so you ONLY get gecko-based browsers:
    Code:
    var ua = navigator.userAgent.toUpperCase();
    if (ua.indexOf('GECKO') != -1 && ua.indexOf('OPERA') == -1 && ua.indexOf('SAFARI') == -1){
      
      /* put your pop up script here */
    }
    The reason? Opera has a "feature" known as user-agent spoofing, where the user can identify his browser as Netscape 6, Netscape 4, IE5, or Opera. No matter what, however, Opera will always have "Opera" in its user-agent string somewhere. Apple put "(like Gecko)" in Safari's UA string so that sites who only look for IE and Gecko will let the browser pass; same deal with Opera, since people don't seem to like coding to standards.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys
    Experience is that thing which lets you know you've made the same mistake yet again.


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
  •