1   // ua.js - Detect Browser
  2  
  3   // Requires JavaScript 1.1
  4  
  5   /*
  6  
  7   The contents of this file are subject to the Netscape Public
  8  
  9   License Version 1.1 (the "License"); you may not use this file
  10  
  11   except in compliance with the License. You may obtain a copy of
  12  
  13   the License at http://www.mozilla.org/NPL/
  14  
  15  
  16  
  17   Software distributed under the License is distributed on an "AS
  18  
  19   IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  20  
  21   implied. See the License for the specific language governing
  22  
  23   rights and limitations under the License.
  24  
  25  
  26  
  27   The Initial Developer of the Original Code is Bob Clary.
  28  
  29  
  30  
  31   Contributor(s): Bob Clary, Original Work, Copyright 1999-2000
  32  
  33                   Bob Clary, Netscape Communications, Copyright 2001
  34  
  35  
  36  
  37   Alternatively, the contents of this file may be used under the
  38  
  39   terms of the GNU Public License (the "GPL"), in which case the
  40  
  41   provisions of the GPL are applicable instead of those above.
  42  
  43   If you wish to allow use of your version of this file only
  44  
  45   under the terms of the GPL and not to allow others to use your
  46  
  47   version of this file under the NPL, indicate your decision by
  48  
  49   deleting the provisions above and replace them with the notice
  50  
  51   and other provisions required by the GPL.  If you do not delete
  52  
  53   the provisions above, a recipient may use your version of this
  54  
  55   file under either the NPL or the GPL.
  56  
  57   */
  58  
  59  
  60  
  61   // work around bug in xpcdom Mozilla 0.9.1
  62  
  63   window.saveNavigator = window.navigator;
  64  
  65  
  66  
  67   // Handy functions
  68  
  69   function noop() {}
  70  
  71   function noerror() { return true; }
  72  
  73  
  74  
  75   function defaultOnError(msg, url, line)
  76  
  77   {
  78  
  79           // customize this for your site
  80  
  81           if (top.location.href.indexOf('_files/errors/') == -1)
  82  
  83                   top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
  84  
  85   }
  86  
  87  
  88  
  89   // Display Error page...
  90  
  91   // XXX: more work to be done here
  92  
  93   //
  94  
  95   function reportError(message)
  96  
  97   {
  98  
  99           // customize this for your site
  100  
  101           if (top.location.href.indexOf('_files/errors/') == -1)
  102  
  103                   top.location = '/evangelism/xbProjects/_files/errors/index.html?msg=' + escape(message);
  104  
  105   }
  106  
  107  
  108  
  109   function pageRequires(cond, msg, redirectTo)
  110  
  111   {
  112  
  113           if (!cond)
  114  
  115           {
  116  
  117                   msg = 'This page requires ' + msg;
  118  
  119                   top.location = redirectTo + '?msg=' + escape(msg);
  120  
  121           }
  122  
  123           // return cond so can use in <A> onclick handlers to exclude browsers
  124  
  125           // from pages they do not support.
  126  
  127           return cond;
  128  
  129   }
  130  
  131  
  132  
  133   function detectBrowser()
  134  
  135   {
  136  
  137           var oldOnError = window.onerror;
  138  
  139           var element = null;
  140  
  141           
  142  
  143           window.onerror = defaultOnError;
  144  
  145  
  146  
  147           navigator.OS            = '';
  148  
  149           navigator.version       = 0;
  150  
  151           navigator.org           = '';
  152  
  153           navigator.family        = '';
  154  
  155  
  156  
  157           var platform;
  158  
  159           if (typeof(window.navigator.platform) != 'undefined')
  160  
  161           {
  162  
  163                   platform = window.navigator.platform.toLowerCase();
  164  
  165                   if (platform.indexOf('win') != -1)
  166  
  167                           navigator.OS = 'win';
  168  
  169                   else if (platform.indexOf('mac') != -1)
  170  
  171                           navigator.OS = 'mac';
  172  
  173                   else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
  174  
  175                           navigator.OS = 'nix';
  176  
  177           }
  178  
  179  
  180  
  181           var i = 0;
  182  
  183           var ua = window.navigator.userAgent.toLowerCase();
  184  
  185           
  186  
  187           if (ua.indexOf('opera') != -1)
  188  
  189           {
  190  
  191                   i = ua.indexOf('opera');
  192  
  193                   navigator.family        = 'opera';
  194  
  195                   navigator.org           = 'opera';
  196  
  197                   navigator.version       = parseFloat('0' + ua.substr(i+6), 10);
  198  
  199           }
  200  
  201           else if ((i = ua.indexOf('msie')) != -1)
  202  
  203           {
  204  
  205                   navigator.org           = 'microsoft';
  206  
  207                   navigator.version       = parseFloat('0' + ua.substr(i+5), 10);
  208  
  209                   
  210  
  211                   if (navigator.version < 4)
  212  
  213                           navigator.family = 'ie3';
  214  
  215                   else
  216  
  217                           navigator.family = 'ie4'
  218  
  219           }
  220  
  221           else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
  222  
  223           {
  224  
  225                   i = ua.lastIndexOf('/')
  226  
  227                   navigator.version = parseFloat('0' + ua.substr(i+1), 10);
  228  
  229                   navigator.family = 'gecko';
  230  
  231  
  232  
  233                   if (ua.indexOf('netscape') != -1)
  234  
  235                           navigator.org = 'netscape';
  236  
  237                   else if (ua.indexOf('compuserve') != -1)
  238  
  239                           navigator.org = 'compuserve';
  240  
  241                   else
  242  
  243                           navigator.org = 'mozilla';
  244  
  245           }
  246  
  247           else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
  248  
  249           {
  250  
  251               var is_major = parseFloat(navigator.appVersion);
  252  
  253      
  254  
  255                   if (is_major < 4)
  256  
  257                           navigator.version = is_major;
  258  
  259                   else
  260  
  261                   {
  262  
  263                           i = ua.lastIndexOf('/')
  264  
  265                           navigator.version = parseFloat('0' + ua.substr(i+1), 10);
  266  
  267                   }
  268  
  269                   navigator.org = 'netscape';
  270  
  271                   navigator.family = 'nn' + parseInt(navigator.appVersion);
  272  
  273           }
  274  
  275           else if ((i = ua.indexOf('aol')) != -1 )
  276  
  277           {
  278  
  279                   // aol
  280  
  281                   navigator.family        = 'aol';
  282  
  283                   navigator.org           = 'aol';
  284  
  285                   navigator.version       = parseFloat('0' + ua.substr(i+4), 10);
  286  
  287           }
  288  
  289  
  290  
  291           navigator.DOMCORE1      = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
  292  
  293           navigator.DOMCORE2      = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
  294  
  295           navigator.DOMHTML       = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
  296  
  297           navigator.DOMCSS1       = ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );
  298  
  299  
  300  
  301           navigator.DOMCSS2   = false;
  302  
  303           if (navigator.DOMCORE1)
  304  
  305           {
  306  
  307                   element = document.createElement('p');
  308  
  309                   navigator.DOMCSS2 = (typeof(element.style) == 'object');
  310  
  311           }
  312  
  313  
  314  
  315           navigator.DOMEVENTS     = (typeof(document.createEvent) != 'undefined');
  316  
  317  
  318  
  319           window.onerror = oldOnError;
  320  
  321   }
  322  
  323  
  324  
  325   detectBrowser();
  326  
  327  
  328