为IE包含​​es6-promise的优雅方式 [英] Elegant way to include es6-promise for IE

查看:172
本文介绍了为IE包含​​es6-promise的优雅方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Promise在所有IE版本中都是不支持, IE用户可以下载HTML中的pollyfill.

Since Promise is not support in all IE versions, I would like to make the IE users to download a pollyfill in HTML.

<!--[if IE]>
<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"></script>
<![endif]-->

但是,不支持条件注释在IE 10和11中.因此上述代码在IE 10和11中不起作用.

However, conditional comments are not supported in IE 10 and 11. So the above code doesn't work in IE 10 and 11.

然后,Microsoft提供一种解决方法.

Then, Microsoft provide a workaround.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">

这使IE 10和11的行为类似于IE9.

This make IE 10 and 11 behave like IE 9.

但是我的网站只能在IE 10+中运行.因此,此解决方案不适合我. 还有其他方法可以解决此问题吗?

But my website work only in IE 10+. So this solution isn't suitable to me. Is there any other way to solve this issue?

推荐答案

只需使用

<script>
    if (typeof Promise !== "function")
        document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><\/script>');
</script>

不仅不适用于IE用户,而且在没有本机Promise实施的每种环境中都适用.

which does not work only for IE users, but in every environment without a native Promise implementation.

这篇关于为IE包含​​es6-promise的优雅方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆