最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - SweetAlert2 syntax error on Internet Explorer 11 - Stack Overflow

programmeradmin8浏览0评论

I'm using the exactly code of SweetAlert2 examples page:

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})

Works fine on Firefox and Chrome, but Internet Explorer shows SCRIPT1002: Syntax Error and not run the script...IE flag this portion as syntax error:

}).then((result) => {

Thanks for any help

I'm using the exactly code of SweetAlert2 examples page:

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.value) {
    swal(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
})

Works fine on Firefox and Chrome, but Internet Explorer shows SCRIPT1002: Syntax Error and not run the script...IE flag this portion as syntax error:

}).then((result) => {

Thanks for any help

Share Improve this question edited Apr 18, 2018 at 10:17 Limon Monte 54.4k48 gold badges187 silver badges219 bronze badges asked Apr 18, 2018 at 10:02 Pedro AntônioPedro Antônio 4051 gold badge7 silver badges19 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 19

(result) => {} is an arrow function which is pletely unsupported in IE. To fix this you'll have to use a traditional anonymous function:

swal({
  // options...
}).then(function(result) {
  if (result.value) {
    swal('Deleted!', 'Your file has been deleted.', 'success');
  }
});

IE11 does not support some modern ES6 features like arrow functions and promises.

To fix it, you should either pile your code with Babel, or use a Promise-polyfill with the traditional function syntax:

swal(...)
  .then(function(result) {
    console.log(result.value)
  })

Read more about SweetAlert2 usage: https://github./sweetalert2/sweetalert2#usage

Aditionally to anonymous functions, to have swal fully functional in IE, its necessary add and script tag

<script src="https://cdnjs.cloudflare./ajax/libs/core-js/2.4.1/core.js"></script>

As seen in https://github./sweetalert2/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2#1-ie-support

To make showLoading() work in IE11 you need to use the promise shim and an anonymous function...

Swal.fire({
    title: "Saving",
    text: "Please wait...",
    onBeforeOpen: function() {
        Swal.showLoading();
    }
});
发布评论

评论列表(0)

  1. 暂无评论