3
  • 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)

ezG
  • 391
  • 1
  • 17
  • Really hard to understand your question without seeing code. – bart Nov 21 '18 at 00:38
  • You should be able to overwrite / set `window.alert` to a custom function that then calls `showNotification`, eg `window.alert = function(){ app.showNotification() }` More than likely would probably need to do this as soon as possible like in `Office.initialize` – Patrick Evans Nov 21 '18 at 00:41
  • @PatrickEvans: **Worked** immediately. THANK YOU! I was able to display my tables. One last question. How do I pass along the text message that was in the alert to the _showNotification_ function? _showNotification_ does accept parameters. – ezG Nov 21 '18 at 01:01
  • Just define the function argument and pass it to showNotification, see the answer i posted to see an example – Patrick Evans Nov 21 '18 at 01:11
  • @ezG can you share your app.showNotification function/implementation? – rocketlobster Aug 23 '19 at 01:43

1 Answers1

1

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)
  };
};
Patrick Evans
  • 41,991
  • 6
  • 74
  • 87
  • @ezG If you satisfied with the answer consider to accept it. Accepting Answers: [How does it work?](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work?answertab=active#tab-top) – Slava Ivanov Nov 22 '18 at 14:34