admin管理员组文章数量:1287181
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/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"></script>
<![endif]-->
However, conditional ments are not supported in IE 10 and 11. So the above code doesn't work in IE 10 and 11.
Then, Microsoft provide a workaround.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
This make IE 10 and 11 behave like IE 9.
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?
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./ajax/libs/es6-promise/4.1.1/es6-promise.min.js"></script>
<![endif]-->
However, conditional ments are not supported in IE 10 and 11. So the above code doesn't work in IE 10 and 11.
Then, Microsoft provide a workaround.
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
This make IE 10 and 11 behave like IE 9.
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?
Share Improve this question edited Aug 4, 2017 at 14:50 cwtuan asked Aug 4, 2017 at 14:45 cwtuancwtuan 1,8611 gold badge19 silver badges23 bronze badges 5-
Are you trying to request the
.js
file at only ie? – guest271314 Commented Aug 4, 2017 at 14:47 - @guest271314 "I would like to make the IE users to download a pollyfill" – Bergi Commented Aug 4, 2017 at 14:47
- @Bergi You quoted the requirement then proceeded to exceed the boundaries that you quoted at Answer? The solution should provide a means for expected result, if not exacting as to actual Question which you quoted. – guest271314 Commented Aug 4, 2017 at 14:50
- @guest271314 A requirement is not a boundary. I'm trying to solve problems instead of taking everything literally. – Bergi Commented Aug 4, 2017 at 14:59
-
@Bergi Yes, though why load the
.js
file at browsers where the file is not necessary? You can checkdocument.body.style
for anMS
prefixed property and then request file if the condition istrue
. Literal interpretation avoids ambiguity as to a specific requirement or topic. Specificity. – guest271314 Commented Aug 4, 2017 at 15:03
2 Answers
Reset to default 10Just use
<script>
if (typeof Promise !== "function")
document.write('<script src="//cdnjs.cloudflare./ajax/libs/es6-promise/4.1.1/es6-promise.min.js"><\/script>');
</script>
which does not work only for IE users, but in every environment without a native Promise
implementation.
Same without the external script
var lPromise = function(handler) {
if (typeof Promise === "function")
return new Promise(handler);
var self = this;
self._handler = handler;
this.then = function(onFulfilled, onRejected) {
this._handler(onFulfilled, onRejected);
}
return self;
}
this.Promise = function(handler) {
return new lPromise(handler);
}
本文标签: javascriptElegant way to include es6promise for IEStack Overflow
版权声明:本文标题:javascript - Elegant way to include es6-promise for IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741306530a2371399.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论