1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
|
varuserAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
jQuery.browser = {
version: (userAgent.match( /.+(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [0,'0'])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
|
发现其匹配到后面一个MSIE: 6.0了,IE8在非兼容模式下的navigator.userAgent大概为:
1
|
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 2.0.50727; CIBA; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
|
将第一个.+使用非贪婪匹配,让他匹配第一个MSIE 8.0,修改第1170行如下:
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
|
varuserAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
jQuery.browser = {
version: (userAgent.match( /.+?(?:rv|it|ra|ie)[/: ]([d.]+)/ ) || [0,'0'])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
|
仅仅是加了个?号啦,不知道为什么jQuery没有修复这个问题,或者说是我理解错误?在最新nightly version中我看他做了一些修改,被移到extend去了:
505
506
507
508
509
510
511
512
513
514
|
// Use of jQuery.browser is deprecated.
// It's included for backwards compatibility and plugins,
// although they should work to migrate away.
browser: {
version: (/.+(?:rv|it|ra|ie)[/: ]([d.]+)/.exec(userAgent) || [0,'0'])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
}
|
貌似也没解决这个问题,依然需要在.+后增加?号才可以正常显示8.0:
505
506
507
508
509
510
511
512
513
514
|
// Use of jQuery.browser is deprecated.
// It's included for backwards compatibility and plugins,
// although they should work to migrate away.
browser: {
version: (/.+?(?:rv|it|ra|ie)[/: ]([d.]+)/.exec(userAgent) || [0,'0'])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
}
|
在公司没办法测试其他浏览器下增加?会不会导致错误,所以这个只是个探讨,晚上回去测试一下Firefox,Safari等看看是否正确。