Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser detection 1

Status
Not open for further replies.

RedRobotHero

Technical User
May 2, 2003
94
CN
So I'm inexperienced in javascript and I'm looking at an example script. This is what it used to detect the browser. I don't know that I fully understand what it is doing.

Code:
var ns6=document.getElementById&&!document.all
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1

Now, I guess the first line is testing whether certain objects exist, which is all well and good. The second line, though, seems to assume that anything that isn't Opera is IE. While that might work for a good portion of the time, there will be exceptions to that rule.

Is this fine the way it is? Or could there be problems with it?
 
well no because document.all is IE only. The 2nd condition in the line is to stop Opera from pretending to be IE.

I think you have to check for "opera " and "opera/" to catch it on any OS but I could be wrong.
 
Actually it could be a little better at catching opera, not creating errors in NN6x and getting IE4 only. This should be IE4 (can't test).

Disregard what I said about "opera/" it's for getting versions.

Code:
var ie4=document.all&&!document.getElementById&&navigator.userAgent.toLowerCase().indexOf("opera")==-1?1:0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top