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 check document.body.style for an MS prefixed property and then request file if the condition is true. Literal interpretation avoids ambiguity as to a specific requirement or topic. Specificity. – guest271314 Commented Aug 4, 2017 at 15:03
Add a ment  | 

2 Answers 2

Reset to default 10

Just 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