Results 1 to 7 of 7

Thread: [JAVASCRIPT] Sniff Opera

  1. #1
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default [JAVASCRIPT] Sniff Opera

    1) CODE TITLE: Sniff Opera

    2) AUTHOR NAME/NOTES: Arie Molendijk

    3) DESCRIPTION: You can sniff Opera through if(history.navigationMode) {bla}.

    I had my doubts about posting this, but a quick search on Google told me that very few coders seem to use it (I found 2 entries only). So this might be a useful (unknown?) piece of code for some of you. If not, tell me, and I'll withdraw the thread.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Opera has its own proprietary window object:

    window.opera

    That's why no one in their right mind would ever look any farther than that for sniffing Opera.

    Usage:

    Code:
    if (window.opera) {
    do opera stuff here
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    John, I recall having read somewhere that older versions of Opera do not support 'if (window.opera)'. As history.navigationMode has been part of Opera all along, I thought that 'if(history.navigationMode)' would be better. But I may very well be wrong on that.
    ---
    Arie.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Sniffing is generally a bad idea however it its done. But when another way cannot be found, it is better than nothing until a better way is devised.

    That said, sniffing for Opera using that older method (if it is as you say, applicable to more versions) would be like sniffing for FF/Netscape using if(navigator.appName=='Netscape'). The number of browsers selected would be so great as to have no practical use for most code branching. It would include at least NN 4 up to the most recent FF release I've seen, the two of which share almost nothing else in common.

    They do both do window.innerWidth I believe. But there are so many others that do as well. At that point, it would be much better to test for the property.

    I'm sure it is much like that with early Opera, and more recent versions. Even those browsers which return true for window.opera have a fairly wide range of feature sets.

    So, although what you've identified may have some utility, it is probably much less than you might imagine. Its greatest value would be in determining whether or not history.navigationMode could be used, that is if that is anything different than history.go. Is it? I mean aside from being a possibility for sniffing, does it do anything?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by jscheuer1 View Post
    So, although what you've identified may have some utility, it is probably much less than you might imagine. Its greatest value would be in determining whether or not history.navigationMode could be used, that is if that is anything different than history.go. Is it? I mean aside from being a possibility for sniffing, does it do anything?
    When you navigate with the Back and Forward buttons, Opera doesn't fire any load and unload events, because it fetches previous pages from its cache. Using
    Code:
    history.navigationMode="compatible"
    instead of
    Code:
    history.navigationMode="fast"
    or
    Code:
    history.navigationMode="automatic"
    (or instead of doing nothing) solves that problem.
    ---
    Arie.
    Last edited by molendijk; 06-01-2008 at 11:48 AM. Reason: Correcting English

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes, I just Googled it while you were posting, of course one would need to:

    Code:
    if (history.navigationMode)
    history.navigationMode = 'compatible';
    or it could create more problems than it would solve. Here is where that 'sniff' should be used, as it's now feature detection, not browser sniffing. In fact, it would generally be preferable to:

    Code:
    if (window.opera)
    history.navigationMode = 'compatible';
    The one (window.opera) having no direct relation to the other (history.navigationMode). It would work out in most if not all modern cases, but only due to coincidence.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Quote Originally Posted by jscheuer1 View Post
    ... of course one would need to:
    Code:
    if (history.navigationMode)
    history.navigationMode = 'compatible';
    or it could create more problems than it would solve. Here is where that 'sniff' should be used, as it's now feature detection, not browser sniffing.
    You're right!
    ---
    Arie.

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
  •