SweetAlert2 syntax error on Internet Explorer 11

Pedro Antônio picture Pedro Antônio · Apr 18, 2018 · Viewed 7.2k times · Source

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

Answer

Rory McCrossan picture Rory McCrossan · Apr 18, 2018

(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');
  }
});