一个具体的问题。我一直在阅读有关如何定位ie10及以下的内容,但实际上还没有找到适合我情况的具体答案。
我正在使用不支持ie10(google聚合物)的网站框架,因此我在用户使用ie10及以下时设置了备用页面。我遇到的问题是,当我在ie10中打开我的网页时,让聚合物运行platform.js
所需的资源导致了很多错误,导致其他资源无法以某种方式加载。 platform.js
位于我的加载顺序的顶部,我不是异步加载。我试图在js文件中定位ie10,该文件必须在platform.js
下面加载,但由于platform.js
造成了很多错误,我的代码根本没有注册。
我想知道如果浏览器是platform.js
,只有加载!ie10
,同时仍然将其置于加载顺序的顶部,是否有办法加载{{1}}。呃这让我疯了。即使是我可以阅读的有关如何仅在某些事件上加载资源的链接也会有所帮助。感谢您的任何信息!
答案 0 :(得分:1)
我终于想出了一种使用Mario's answer here的方法,以防将来有人感兴趣:
我在index.html文件的头部开头弹出了这个:
<script>
function detectIE() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
var trident = ua.indexOf('Trident/');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
if (trident > 0) {
// IE 11 (or newer) => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
// other browser
return false;
}
// making sure it's working..
console.log(detectIE());
// this is important: if you just say <= 10 then it will also accept ZERO
// and ZERO is = false, which makes good browsers like Chrome detect as IE
if (detectIE() >= 1 && detectIE() <= 10) {
console.log('this is below ie10');
} else {
// add my script for polymer
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "/bower_components/platform/platform.js";
//put it at the start of the head tag
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
我注意到网站首次加载时会出现一点点滞后现象,但这并不算太糟糕。这将是必须要做的,直到我更好地使用Modernizr之类的东西。