我使用以下脚本片段:
if ($.browser.msie && $.browser.version < 9) {
extra = "?" + Math.floor(Math.random() * 3000);
}
它在jQuery 1.8.3上运行良好。
现在,我将jQuery更新到新版本的1.9.1,以使用新脚本。
现在我得到以下错误:
TypeError:无法读取未定义的属性“”msie“”
我阅读了新jQuery版本的更改日志,但应该没有任何更改
和msie在一起
有任何已知的bug、提示或建议吗?
发布于 2013-02-15 17:57:15
$.browser
在1.3版中已弃用,并在1.9版中被删除
您可以通过查看documentation验证这一点。
发布于 2013-02-15 18:00:10
由于$.browser已被弃用,这里有一个替代解决方案:
/**
* Returns the version of Internet Explorer or a -1
* (indicating the use of another browser).
*/
function getInternetExplorerVersion()
{
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();
if ( ver > -1 )
{
if ( ver >= 8.0 )
msg = "You're using a recent copy of Internet Explorer."
else
msg = "You should upgrade your copy of Internet Explorer.";
}
alert( msg );
}
但是,它被弃用的原因是因为jQuery希望您改用feature detection。
举个例子:
$("p").html("This frame uses the W3C box model: <span>" +
jQuery.support.boxModel + "</span>");
最后但并非最不重要的是,检查IE版本的最可靠方法:
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
// And to detect the version:
// ie === 6 // IE6
// ie > 7 // IE8, IE9 ...
// ie < 9 // Anything less than IE9
// ----------------------------------------------------------
// UPDATE: Now using Live NodeList idea from @jdalton
var ie = (function(){
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
发布于 2013-12-29 22:15:49
对于简单的IE检测,我倾向于使用:
(/msie|trident/i).test(navigator.userAgent)
访问微软开发人员网络以了解IE用户代理:http://msdn.microsoft.com/library/ms537503.aspx
https://stackoverflow.com/questions/14892095
复制相似问题