1

I'm new to office js. Just I need to show prompt alert box using office Js but Javascript alert not working inside office js. Can someone help me to do this?

Expected alert box

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
gasp porch
  • 31
  • 1

1 Answers1

2

You can use the Office dialog API to open dialog boxes in your Office Add-in.

To open a dialog box, your code, typically a page in a task pane, calls the displayDialogAsync method and passes to it the URL of the resource that you want to open. The page on which this method is called is known as the "host page". For example, if you call this method in script on index.html in a task pane, then index.html is the host page of the dialog box that the method opens.

The resource that is opened in the dialog box is usually a page, but it can be a controller method in an MVC application, a route, a web service method, or any other resource. The page or website refers to the resource in the dialog box. The following code is a simple example:

Office.context.ui.displayDialogAsync('https://yourAddinDomain/yourDialog.html');

Read more about that in the Use the Office dialog API in Office Add-ins article.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi @Eugene Astafiev. Thanks for your answer. It's working fine. How to remove or change host name and host parameters in thar dialog box ( eg : https://localhost:3000/popup-custom.html ) – gasp porch Jan 20 '23 at 13:07
  • When you change the localhost URL to any real web server they should disappear. Only Outlook for Desktop may display such weird captions after that. – Eugene Astafiev Jan 20 '23 at 13:31
  • Thanks. Is there any other option to achieve dialog or alert box in excel addins ? I gave my expected alert box in my question. pls check and help me to do this – gasp porch Jan 28 '23 at 09:05
  • No, you need to use the Office dialog API like described in my post. – Eugene Astafiev Jan 28 '23 at 09:56