最近,Chrome deprecated NPAPI support,这意味着没有Silverlight。现在,我已经学会了成为一名优秀的Web开发人员,并且更喜欢通过浏览器检测进行功能检测,以提供良好的用户体验。不幸的是,seems impossible正确地进行了NPAPI支持功能检测。
我为Silverlight工具构建了一个JavaScript替代品。我最初使用conditional comments检查用户是否在IE9或更早版本,这是一种可靠的方法(如果我错了,请纠正我)。在那种情况下,我会为他们提供Silverlight工具。假设其他浏览器支持所有必要的功能(在这种情况下我们仅针对桌面浏览器),因此它们被提供给新的JS工具。
经过测试,结果发现IE10和IE11太慢,无法很好地处理我们的应用程序。特别是一些I / O操作(MD5 hashing和DICOM parsing)约为。慢了10-15倍。我以为我只是为所有版本的IE提供Silverlight工具,但conditional comments are no longer supported in IE10+。
我被撕裂了。毕竟我似乎不得不求助于不可靠的浏览器检测。我唯一的选择似乎是testing if the JS engine is slow,但这似乎也不可靠。所以我转向StackOverflow的优秀人才;该怎么办?
答案 0 :(得分:0)
很遗憾没有人有更好的建议。最后,我能够为Silverlight控件编写纯JavaScript替代品。由于IE10和IE11的I / O操作性能仍然很差,我决定检测它们以回退到Silverlight控件。
<!--[if IE]>
<script type="text/javascript">
window.is_ie = true;
</script>
<![endif]-->
<script type="text/javascript">
function isIE(ua) {
if (ua.indexOf('MSIE ') > -1)
return true;
if (ua.indexOf('Trident/') > -1)
return true;
return false;
}
if(!window.is_ie) {
window.is_ie = isIE(window.navigator.userAgent);
}
</script>