Web browser detection: Opera

For any useful advice you want to share, on any subject under the sun.

Moderator: Thought Police

Locked
heavy-rotation
Thought Police
Thought Police
Posts: 1205
Joined: Thu Mar 14, 2002 12:11 pm
Location: Macclesfield
Contact:

Web browser detection: Opera

Post by heavy-rotation »

If you need to detect Opera as it's not rendering something or other properly, or some javascript isn't working, try this:

Code: Select all

operaOrOtherSneakyBrowser = (navigator.appVersion.indexOf ('MSIE') && typeof ActiveXObject == "undefined")

alert (operaOrOtherSneakyBrowser)
the sneaky gits set the user agent to IE by default, so you have to do a further test to make sure they're really not lieing (the ActiveXObject bit).
Last edited by heavy-rotation on Thu Jun 19, 2003 5:41 pm, edited 1 time in total.
Sanglier
Delta (Bokanovsky)
Delta (Bokanovsky)
Posts: 219
Joined: Tue Aug 13, 2002 12:38 pm
Location: France

Post by Sanglier »

This might be to get around MSN deliberately screwing up output for non-IE browsers.....
heavy-rotation
Thought Police
Thought Police
Posts: 1205
Joined: Thu Mar 14, 2002 12:11 pm
Location: Macclesfield
Contact:

Post by heavy-rotation »

I know, but it doesn't exactly help when it decides it will behave a little differently and I still need to write around it ;)
Nat
Alpha (Conditioned)
Alpha (Conditioned)
Posts: 1227
Joined: Tue Apr 23, 2002 5:56 pm
Location: Half way down a midge infested moor, Unscotlandland
Contact:

Post by Nat »

Good one - thanks Gary :) I was wondering about that a while back and couldn't be arsed to find a workaround (its only Opera :D), but now I have no excuse ;)
"Sometimes democracy must be bathed in blood" - Augusto Pinochet
Kajun
World Controller
World Controller
Posts: 10412
Joined: Tue Jan 22, 2002 12:00 am
Location: Hear.
Contact:

Post by Kajun »

Possible use?
Kajun is awaiting approval.
heavy-rotation
Thought Police
Thought Police
Posts: 1205
Joined: Thu Mar 14, 2002 12:11 pm
Location: Macclesfield
Contact:

Post by heavy-rotation »

It wasn't behaving with a menu system I made - seemed to be having some trouble coming to grips with float:left styles being used on images. as it turns out, I didn't need those (and therefore this detection) in the end anyway, but it may be of some use in the future.

Actually, I'm rather impressed with Opera 7. Finally sorted out the previously dire JS support, even to the point it has old ie style document.all. :)
Locked