SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: detecting opera

  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    detecting opera

    is window.opera really the best way to single out Opera?

    i have a page where positioning for an h4 element is ok except in Opera9 so I wrote:

    if(window.opera){
    changeStyleHere;
    }

    is this the best way?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    What is the positioning situation that causes Opera trouble?
    There should be a more standards compliant way to resolve the issue.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,448
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    if Opera

    I don't know if it's "best", but I have a script on my blog that uses
    HTML Code:
    if (navigator.userAgent.indexOf('Opera') != -1) {
    to handle window height/width differences

    Note* Opera lets users choose the identity of the browser so this isn't 100% reliable.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's why window.opera is a better solution than sniffing the UA string, in the off chance that you really need special handling for Opera.
    Birnam wood is come to Dunsinane

  5. #5
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems like object detection would be the better way, I don't think any other UA has opera as a property of window.

  6. #6
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the feedback. So, if a users changes the identity of Opera, won't window.opera still work because it is detecting a property of the browser itself?

    What is the positioning situation that causes Opera trouble?
    There should be a more standards compliant way to resolve the issue.
    I had a series of div's (which probably should have been in a ul element but wasn't) and an h4 element inside. the vertical positioning was fine in every browser except opera, it was too high. it needed 15px top padding to match other browsers. but if i just added that padding in the css, other browsers (i.e. moz, ff, ie6/7, saf) would sit to low. after spending hours getting nowhere i decided to cheat and set the positioning with js. i feel like i tried every combination of changing the padding / margin but the case was always - opera ok, everything else too low or opera to high, everything else good.

    i think i took the easy way out but i had to move on.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Can you please provide us with a code sample?
    If we come up with a more appropriate fix for this issue, then others may be able to benefit from this.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •