如何禁用仅适用于IE11的内联脚本



我注意到在IE11上,这个脚本真的把滚动搞砸了。其他浏览器也可以。所以我想知道如何仅在IE11上排除它。

var $t            = $(this),
$w            = $(window),
viewTop       = $w.scrollTop(),
viewBottom    = viewTop + $w.height(),
_top          = $t.offset().top,
_bottom       = _top + $t.height(),
compareTop    = partial === true ? _bottom : _top,
compareBottom = partial === true ? _top : _bottom;
return ((compareBottom <= viewBottom) && (compareTop >= viewTop));

您可以参考以下代码来检查浏览器是IE还是其他浏览器:

<script type="text/javascript">
function msieversion() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv:11./))  // If Internet Explorer, return version number
{
alert("IE ");
}
else  // If another browser, return 0
{
alert('otherbrowser');
}
return false;
}
</script>

来自此线程的代码

最新更新