alek kowalczyk
alek kowalczyk

Reputation: 4934

Outlook Javascript API - window.open not working from Outlook 2016 Desktop/Windows

I have an Office Add-In written in the new JavaScript API, inside of it, I have a JS function which after some logic opens a web app in a new window using window.open(url, '_blank')

It works when called from the add-in pane in Outlook Web in both, localhost hosted add-in, as well as after deployment on heroku.

However when called from a command (add-in button on ribbon) it works only when the add-in is hosted on localhost, after I deploy it on heroku, the add-in works, shows commands in the ribbon, performs the JS logic, but window.open does nothing.

Looks like the only way to open a new window is by using Office.context.ui.displayDialogAsync but even then it works only if the page is on the same origin as the add-in code.

I would think that there are some security restrictions, but why then it worked when hosted on localhost? Is there any way, to open a browser window from a command in Outlook using the new Javascript API?

Upvotes: 2

Views: 1740

Answers (2)

Ava
Ava

Reputation: 337

My experience with this has been that window.open is not consistently reliable across the different platforms, which sort of forces you to use Office.context.ui.displayDialogAsync. As you mentioned, it fusses at you if you try to open a page that's not on your domain. I've found there's a couple of ways around this that might be viable depending on your usage scenario:

  1. You can update the <AppDomains> section of your manifest to include the site you want to open up the window to. This section acts as a sort of white list.
  2. You can point to a page within your domain that's soul purpose is to redirect you somewhere else. I haven't run into restrictions on redirecting the window, just opening it. I use this method along with qstring parameters to control the redirect as needed.

Upvotes: 1

darshil.chapadia
darshil.chapadia

Reputation: 506

I think window.location.href will work for you.

window.location.href = URL

Upvotes: 0

Related Questions