SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,

    I have 1 client-side and 1 server-side browser detection script.
    None can differentiate between IE and Opera.
    Basically, it just detects opera as being IE.

    Is there a way whereby I can have opera detected as 'OPERA'? // thanks!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Opera developers built an option into Opera so that it can identify itself as another type/version of browser because a lot of js was/is written to only detect IE or Netscape. I think by default this setting may be IE but it can be changed in File > Preferences > Connections > Broswer Identification.

    You can see the results of changing the setting at http://javascript.internet.com/user-...r-details.html.

    I think if Opera users haven't got Opera to identify itself as Opera then there may not be any way of knowing that it is in fact Opera. (But I'm definately no js expert, so I could be wrong.)

    Hope this helps.

  3. #3
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    GRR! Lame lame lame opera developers!
    Now How am I suppose to detect Opera?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  4. #4
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha! Nothing is impossible (*evil laugh*)

    I got it! heehz

    here's it:

    -----------------------------------------------------------
    <script type="text/javascript">

    function Is () {
    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
    && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
    && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    this.gecko = (agt.indexOf('gecko') != -1);
    this.ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.opera = (agt.indexOf("opera") != -1);
    }

    var is;
    is = new Is();

    if (is.gecko) { document.write('<body>'); } // Gecko Engine
    else if (is.nav) { document.write('<body marginwidth="0" marginheight="0">'); } // Netscape Browser
    else if (is.ie) { document.write('<body>'); // IE Browser }
    else if (is.opera) { document.write('<body marginwidth="0" marginheight="0">'); } // Opera Browser
    else { document.write('<body>'); } // All Others
    </script>
    -----------------------------------------------------------


    If you noticed, modify the code within document.write to customise the code for either browser type.

    Note: Netscape 6 and Mozilla comes under Gecko (perfect! with the standards currently being supported)
    Opera detection works even if the user selects IE or NS etc. as the detection in your preferences.

    The reason why i didn't bother about setting browser versions is the older browsers, 3.0 and below won't even matter if i place either codes. since they won't understand it. hence i left it out.


    I used the baove code to set my default style sheets for IE/NS/Gecko and the <body> tag which sets the marginheight etc. (I use CSS for Gecko/IE and the marginheight++ for Netscape4/Opera)

    Here's the code below.

    -----------------------------------------------------------
    <script type="text/javascript">
    <!--
    if (is.nav4) { document.write('<link rel="stylesheet" type="text/css" href="ns.css">'); } // Netscape Browser (Excluding Gecko)
    else { document.write('<link rel="stylesheet" type="text/css" href="style.css">') } // All Others
    //-->
    </script>

    <script type="text/javascript">
    <!--
    if (is.nav4) { document.write('<body marginwidth="0" marginheight="0">'); } // Netscape Browser
    else if (is.opera) { document.write('<body marginwidth="0" marginheight="0">'); } // Opera Browser
    else { document.write('<body>'); } // All Others
    //-->
    </script>
    -----------------------------------------------------------

    Note, the above code assumes you have already placed the javascript code (the function Is). Note that i used nav4 instead as somehow, Mozilla/NS 6 will detect the nav and use Netscpae4's desired code instead. (Mozilla/NS6 returns true when detecting Netscape. As Gecko comes after the NS detection, use nav4 instead of nav when doing specific code for Gecko)


    Hope it'll do some good.. and oh yes, with due recognition, The Ultimate JavaScript Client Sniffer, Version 3.02

    They moved the page form Netscape to Mozilla. Heck..No wonder I oculdn't find it at first
    http://www.mozilla.org/docs/web-deve...r_type_oo.html


    P.S. If you are a w3c standard freak like me, the codes validates perfectly well Enjoy!
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this.opera = (agt.indexOf("opera") != -1);
    Still won't work because of the very reason already outlined. If you change Opera's Id to something otherthan Opera, it won't just change its appName, but also the user agent string.

    The only reliable way to determine Opera is through the DOM. Opera, you see, supports all three DOMs - MS, NS and W3C. So, you can say ...

    var isOpera = (document.all && document.getElementById && document.layers) ? true : false ;

    ///

    This is fool proof, since Opera is the only browser to support all three DOMs. IE supports two - document.all and document.getElementById - whereas the two strands of Netscape support one each.

    There is another method to detect Opera and that is ...

    var isOpera = (window.opera) ? true : false ;

    ///

    However, I believe this'll only work if the user hasn't decided to hide the identity of Opera behind another browser Id.


  6. #6
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm..scot-bot. but i tried it in opera. changing the preferences and it still loaded properly.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm... indeed. what exactly did you try, what was the expected outcome and what exactly happened?

  8. #8
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    okie. i used the code to test the loading of specific style sheets and <body marginheight> blah.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, try this


    <head>
    <script>
    <!--
    function detectOpera()
    {
    var isOpera = (document.all && document.getElementById && document.layers) ? true : false ;

    if (isOpera) alert('is Opera') ;
    else alert('is not Opera') ;
    }

    //-->
    </script>
    </head>


    <body onLoad="detectOpera()"> </body>



    // this should tell you once and for all.

  10. #10
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait wait. if you want testing, use my script above. i tested the code before implementing it. like that you did..
    is opera etc.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  11. #11
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just tried the second method I suggested, i.e. the window.opera method, and it worked perfectly.

    But I'm confused, since the first method I've written for my companies website, and it works fine for it. :

  12. #12
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh. haha.
    nono..i dind't say it didn't work. just said that mine worked. too lazy to try it out! haha...lol


    you wanna give mine a shot?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  13. #13
    SitePoint Enthusiast
    Join Date
    Aug 2000
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lynlimz, the way you customize the page tags depending of the browser type is quite interesting. However i think that you may have some trouble doing so with Opera (at the moment Opera doesn't support the document.write ...as well as few other like innerhtml, layer cliping ...).

    Scot-Bot i like the way you detect Opera. I wasn't aware that it was supporting the 3 DOM.
    When (trying) to detect Opera I usually use something like this >
    (document.getElementById && !document.all && !document.layers)
    As strange as it seems it has been working quite well. Which in a certain way surprise me because if it is supporting the 3 differents DOM it shouldn't.
    I'm going to give a try to you "Opera detect". Thanks for the tip !


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
  •