/    Sign up×
Community /Pin to ProfileBookmark

firefox / opera detection

Can anyone tell me how to simply detect in javascript if the user has an Opera or Firefox browser.

I use document.all to find out if its IE but if it isn’t how can I tell the difference between Firefox and Opera?

Incidentally can anyone tell me how Opera deals with:

In IE – event.returnValue = false
In Firefox – event.preventDefault()

What is the Opera version of this please.

Have to say this is my first foray into the world of browser variations. I am about to give up and just write html! I assumed as lots of people keep saying use ‘real’ browsers like Firefox and Opera that they would implement things the same way. And Firefox truncates title text! Handy that.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 17.2005 — alert(window.opera);
Copy linkTweet thisAlerts:
@CharlesApr 17.2005 —  I am about to give up and just write html! [/QUOTE]You can't go wrong with that. Just write for the standards and all will be well. But if you must...alert (navigator.appName)
Copy linkTweet thisAlerts:
@FangApr 17.2005 — [I]navigator.appName[/I] In Opera this can be changed/faked (Tools > Preferences > Network > Browser ID)

Go for standards ?
Copy linkTweet thisAlerts:
@CharlesApr 17.2005 — [I]navigator.appName[/I] In Opera this can be changed/faked [/QUOTE]It is considered polite when attending a masquerade to not see through anyone's disguise. If users are cloaking the appName of their browser then that is their concern and not yours. To do otherwise would be impolite.
Copy linkTweet thisAlerts:
@WebskaterauthorApr 18.2005 — If I write

alert(navigator.appName) on one of my pages:

using IE an alert box displays with 'Microsoft Internet Explorer' in it.

Using Firefox - no alert box.

Using Opera - no alert box.
Copy linkTweet thisAlerts:
@FangApr 18.2005 — Must be something wrong on the page.

Firefox gives "Netscape"

Opera gives "Opera", "Microsoft Internet Explorer" or "Netscape"
Copy linkTweet thisAlerts:
@WebskaterauthorApr 18.2005 — Thanks for your answers.

What was wrong? Another little wrinkle.

Just writing alert(navigator.appName) anywhere between script tags and IE showed the alert. The others didn't. They wanted it in a function on called by an event.
Copy linkTweet thisAlerts:
@FangApr 18.2005 — Either there is something IE specific when calling the alert or the other browsers have JavaScript disabled.
Copy linkTweet thisAlerts:
@felgallApr 18.2005 — I have a script that will correctly identify any one of a dozen or so different browsers at [URL=http://javascript.about.com/library/blbrsdet.htm]Browser Detection[/URL]. It examines the useragent for various different strings and will correctly identify the browser even if it is masquerading as IE. Useful for when IE specific code doesn't work in Opera for example. Also note that document.all wont identify IE specifically as Opera also recognises it.
Copy linkTweet thisAlerts:
@WebskaterauthorApr 19.2005 — Thanks very much for that.
×

Success!

Help @Webskater spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...