Browser detection
Posted: Thu Aug 17, 2006 7:49 pm
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?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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...
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>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..
Code: Select all
if (method) {
statements
}Code: Select all
function someFunction() {
if(document.getElementById) {
statements using getElementByID
}
}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?
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;