由于Promise在所有IE版本中都是not support的,所以我想让IE用户下载一个用HTML填充的pollyfill。
<!--[if IE]>
<script src="//cdnjs.cloudflare.com/ajax/libs/es6-promise/4.1.1/es6-promise.min.js"></script>
<![endif]-->但是,IE 10和11中的conditional comments are not supported。所以上面的代码在IE 10和11中不起作用。
然后,Microsoft提供了一种解决方法。
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">这使得IE 10和11的行为类似于IE 9。
但我的网站只能在IE 10+中使用。所以这个解决方案不适合我。有没有其他方法来解决这个问题?
发布于 2017-08-04 22:48:59
只需使用
<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实现的环境。
发布于 2018-03-23 05:09:10
不使用外部脚本也是如此
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);
}
https://stackoverflow.com/questions/45509701
复制相似问题