/* Script Name: Full Featured Javascript Browser/OS detection Authors: Harald Hope, Tapio Markula, Websites: http://techpatterns.com/ http://www.nic.fi/~tapio1/Teaching/index1.php3 Script Source URI: http://techpatterns.com/downloads/browser_detection.php Version 3.0.1 Copyright (C) 29 June 2007 ****************************************************************** ALERT: THIS VERSION IS OBSOLETE. IT HAS BEEN REPLACED BY TWO SCRIPTS, AVAILABLE HERE: http://techpatterns.com/downloads/javascript_browser_detection.php if you are looking for php browser detection, you can find that here: http://techpatterns.com/downloads/php_browser_detection.php The javascript browser detection versions on this page are no longer maintained, and will not give as good results as the scripts that replaced them, which can be downloaded if you go to the link above. ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt Coding conventions: http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3 */ /************************************************************* Full version, use it if you are pushing css to its functional limits, and/or are using specialized javascript. Remember, always use method or object testing as your first choice, for example, if ( dom ) { statement; }; This browser detection includes all possibilities I think for most browsers. Let me know if you find an error or a failure to properly detect, or if there is a relevant browser that has special needs for detection at tech@techpatterns.com The main script is separated from the initial netscape 4 detection due to certain bugs in netscape 4 when it comes to unknown things like d.getElementById. The variable declarations of course are made first to make sure that all the variables are global through the page, otherwise a javascript error will occur because you are trying to use an undeclared variable. We test for both browser type (ie, op, or moz/netscape > 6) and version number, then place the version number into a variable which can be tested for < or > values, such as if (moz && moznu>1.1){....statement....;} This seems quite reliable, especially for Opera and Mozilla, where there is no other easy way to get the actual version number. For more in depth discussion of css and browser issues go to: http://www.nic.fi/~tapio1/Teaching/DynamicMenusb.php#detections http://www.nic.fi/~tapio1/Teaching/FAQ.php3 The cover page is at: http://www.nic.fi/~tapio1/Teaching/index1.php3 ***************************************************************/ //initialization, browser, os detection var d, dom, ie, ienu, ie4, ie5, ie5x, ie6, moz, moz_rv, moz_rv_sub, mac, win, old, lin, ie5mac, ie5xwin, op, opnu, op4, op5, op6, op7; d=document; n=navigator; nav=n.appVersion; nan=n.appName; nua=n.userAgent; win=(nav.indexOf('Win')!=-1); mac=(nav.indexOf('Mac')!=-1); lin=(nua.indexOf('Linux')!=-1); // begin primary dom/ns4 test // this is the most important test on the page if ( !document.layers ) { // check if not ns 4, if the browser is dom capable dom = ( d.getElementById ) ? d.getElementById : false; } else { dom = false; } // end main dom/ns4 test old=(nav.substring(0,1)<4); op=(nua.indexOf('Opera')!=-1); moz=(nua.indexOf('Gecko')!=-1); ie=(d.all&&!op); if (op){ op_pos=nua.indexOf('Opera'); opnu=nua.substr((op_pos+6),4); op5=(opnu.substring(0,1)==5); op6=(opnu.substring(0,1)==6); op7=(opnu.substring(0,1)==7); } else if (moz){ rv_pos=nua.indexOf('rv'); moz_rv=nua.substr((rv_pos+3),3); moz_rv_sub=nua.substr((rv_pos+7),1); if(moz_rv_sub==' '||isNaN(moz_rv_sub)){moz_rv_sub='';} moz_rv=moz_rv+moz_rv_sub; } else if (ie){ ie_pos=nua.indexOf('MSIE'); ienu=nua.substr((ie_pos+5),3); ie4=(!dom); ie5=(ienu.substring(0,1)==5); ie6=(ienu.substring(0,1)==6); } else {} /*ie5x tests only for functionavlity. dom or ie5x would be default settings. Opera will register true in this test if set to identify as IE 5*/ ie5x = ( d.all && dom ); ie5mac = ( mac && ie5 ); ie5xwin = (win && ie5x ); /************************************************************** Lite version, tests only for main types and browsers out there, this will cover you in almost all normal situations out there. ***************************************************************/ var d, dom, ie, ie4, ie5x, moz, mac, win, lin, old, ie5mac, ie5xwin, op; d = document; n = navigator; na = n.appVersion; nua = n.userAgent; win = ( na.indexOf( 'Win' ) != -1 ); mac = ( na.indexOf( 'Mac' ) != -1 ); lin = ( na.indexOf( 'Linux' ) != -1 ); if ( !d.layers ){ dom = ( d.getElementById ); op = ( nua.indexOf( 'Opera' ) != -1 ); konq = ( nua.indexOf( 'Konqueror' ) != -1 ); saf = ( nua.indexOf( 'Safari' ) != -1 ); moz = ( nua.indexOf( 'Gecko' ) != -1 );// will be true for safari as well ie = ( d.all && !op ); ie4 = ( ie && !dom ); /* ie5x tests only for functionality. ( dom||ie5x ) would be default settings. Opera will register true in this test if set to identify as IE 5 */ ie5x = ( d.all && dom ); ie5mac = ( mac && ie5x ); ie5xwin = ( win && ie5x ); } /******************************************************** here is a sample use of the browser detector, it would load a browser specific stylesheet for certain unsupported or improperly supported mac ie 5 css styles. The depth variable is used so that the javascript library file can be used from anywhere in the website, you simply insert the depth of the file like this, ... Browser information Page