Reputation: 1861
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]-->
However, conditional comments 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?
Upvotes: 2
Views: 7661
Reputation: 86
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);
}
Upvotes: 1
Reputation: 665130
Just use
<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>
which does not work only for IE users, but in every environment without a native Promise
implementation.
Upvotes: 10