Browser detection
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Browser detection
I need a well maintained script/API which I can include in my apps to to determine which browser I'm dealing with???
Anyone know of one?
Anyone know of one?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
On the PHP side?
get_browser() .. I've posted a purely php version too, viewtopic.php?p=237279#237279
get_browser() .. I've posted a purely php version too, viewtopic.php?p=237279#237279
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Hockey, if I may ask, for what do you need the script?
If it is only for the layout/css I would strongly advice against using a browser detection script. Certainly not javascript. The recommended way is conditional comments to feed IE 5,6 or both their own stylesheet. Only if really necessary. If you need the script for something else I'll shut up..
If it is only for the layout/css I would strongly advice against using a browser detection script. Certainly not javascript. The recommended way is conditional comments to feed IE 5,6 or both their own stylesheet. Only if really necessary. If you need the script for something else I'll shut up..
- christian_phpbeginner
- Forum Contributor
- Posts: 136
- Joined: Sat Jun 03, 2006 2:43 pm
- Location: Java
Hi, give this link a try:Hockey wrote:Something as simple as version and browser type
Primarily:
- IE
- FF
- NS
- OP
Would suffice, as I don't plan on supporting any others...
http://www.w3schools.com/js/tryit.asp?f ... js_browser
Firefox browser will be detected as Netscape. You can however detect mozilla by using the navigator.appCode object.
See the detailed code below which I pasted from http://www.w3schools.com/js/tryit.asp?f ... serdetails:
Code: Select all
<script type="text/javascript" language = "javascript">
function getBrowserSpec() {
document.write("<p>Browser: ");
document.write(navigator.appName + "</p>");
document.write("<p>Browserversion: ");
document.write(navigator.appVersion + "</p>");
document.write("<p>Code: ");
document.write(navigator.appCodeName + "</p>");
document.write("<p>Platform: ");
document.write(navigator.platform + "</p>");
document.write("<p>Cookies enabled: ");
document.write(navigator.cookieEnabled + "</p>");
document.write("<p>Browser's user agent header: ");
document.write(navigator.userAgent + "</p>");
</script>Cheers,
Chris
Last edited by christian_phpbeginner on Fri Aug 18, 2006 2:40 pm, edited 2 times in total.
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
I need it to perform conditional testing inside a javascriptmatthijs wrote:Hockey, if I may ask, for what do you need the script?
If it is only for the layout/css I would strongly advice against using a browser detection script. Certainly not javascript. The recommended way is conditional comments to feed IE 5,6 or both their own stylesheet. Only if really necessary. If you need the script for something else I'll shut up..
So I can adjust it to work on as many browsers as possible...not selecting CSS, etc...
Cheers
Ok. I was afraid you were going to use it for css.. 
Well, about javascript. I know Jeremy Keith (of domscripting) is a proponent of Object detection instead of browser detection.
Something like this:
example
Don't know if you thought about that?
Well, about javascript. I know Jeremy Keith (of domscripting) is a proponent of Object detection instead of browser detection.
Something like this:
Code: Select all
if (method) {
statements
}Code: Select all
function someFunction() {
if(document.getElementById) {
statements using getElementByID
}
}Don't know if you thought about that?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
I prefer that way of determination too.matthijs wrote:Code: Select all
function someFunction() { if(document.getElementById) { statements using getElementByID } }
Don't know if you thought about that?
The old fashion codes
Code: Select all
var isKHTML = navigator.appVersion.match(/Konqueror|Safari|KHTML/);
var isOpera = navigator.userAgent.indexOf('Opera') > -1;
var isIE = !isOpera && navigator.userAgent.indexOf('MSIE') > 1;
var isMoz = !isOpera && !isKHTML && navigator.userAgent.indexOf('Mozilla/5.') == 0;