获得当前浏览器JS的版本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获得当前浏览器JS的版本相关的知识,希望对你有一定的参考价值。
1 获得当前浏览器JS的版本 2 function getjsversion(){ 3 var n = navigator; 4 var u = n.userAgent; 5 var apn = n.appName; 6 var v = n.appVersion; 7 var ie = v.indexOf(‘MSIE ‘); 8 if (ie > 0){ 9 apv = parseInt(i = v.substring(ie + 5)); 10 if (apv > 3) { 11 apv = parseFloat(i); 12 } 13 } else { 14 apv = parseFloat(v); 15 } 16 var isie = (apn == ‘Microsoft Internet Explorer‘); 17 var ismac = (u.indexOf(‘Mac‘) >= 0); 18 var javascriptVersion = "1.0"; 19 if (String && String.prototype) { 20 javascriptVersion = ‘1.1‘; 21 if (javascriptVersion.match) { 22 javascriptVersion = ‘1.2‘; 23 var tm = new Date; 24 if (tm.setUTCDate) { 25 javascriptVersion = ‘1.3‘; 26 if (isie && ismac && apv >= 5) javascriptVersion = ‘1.4‘; 27 var pn = 0; 28 if (pn.toPrecision) { 29 javascriptVersion = ‘1.5‘; 30 a = new Array; 31 if (a.forEach) { 32 javascriptVersion = ‘1.6‘; 33 i = 0; 34 o = new Object; 35 tcf = new Function(‘o‘, ‘var e,i=0;try{i=new Iterator(o)}catch(e){}return i‘); 36 i = tcf(o); 37 if (i && i.next) { 38 javascriptVersion = ‘1.7‘; 39 } 40 } 41 } 42 } 43 } 44 } 45 return javascriptVersion; 46 } 47 48 49 获取当前点击事件的Object对象 50 function getEvent() { 51 if (document.all) { 52 return window.event; //如果是ie 53 } 54 func = getEvent.caller; 55 while (func != null) { 56 var arg0 = func.arguments[0]; 57 if (arg0) { 58 if ((arg0.constructor == Event || arg0.constructor == MouseEvent) 59 || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) { 60 return arg0; 61 } 62 } 63 func = func.caller; 64 } 65 return null; 66 }; 67
以上是关于获得当前浏览器JS的版本的主要内容,如果未能解决你的问题,请参考以下文章