Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function window.alert is not supported

  • Project: Office Add-In
  • Office-UI-Fabric-JS: 1.5.0
  • Fabric Core: 5.0.1

I'm getting the error Function window.alert is not supported

The 3rd party library I'm using ("DataTables") uses the "alert" API.

Is there a way, other than manually modifying the Javascript in "DataTables", to replace the calls to "alert"

It would be nice if I could have the calls to "alert" be routed to app.showNotification() (this call is provided in App.js; a file that is normally found in the Office Add-in examples found on GitHub)

like image 972
ezG Avatar asked Jul 16 '26 04:07

ezG


1 Answers

Overwrite window.alert with a function that will pass on the arguments to app.showNotification()

//if Office supports arrow functions
window.alert = message=>app.showNotification("Title",message);

//otherwise use a normal function expression
window.alert = function(message){
  app.showNotification("Title",message)
};

Should probably do this in the Office.initialize handler so that it happens as soon as possible:

Office.initialize = function(){
  window.alert = function(message){
    app.showNotification("Title For the Notification",message)
  };
};
like image 196
Patrick Evans Avatar answered Jul 17 '26 18:07

Patrick Evans