6

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

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
Pedro Antônio
  • 395
  • 1
  • 6
  • 19

4 Answers4

19

(result) => {} is an arrow function which is completely 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');
  }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
4

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

To fix it, you should either compile 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.com/sweetalert2/sweetalert2#usage

Limon Monte
  • 52,539
  • 45
  • 182
  • 213
0

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

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

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

Pedro Antônio
  • 395
  • 1
  • 6
  • 19
0

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();
    }
});
Kevin
  • 121
  • 1
  • 4