Outlook Javascript API-window.open在Outlook 2016桌面/Windows中不起作用 [英] Outlook Javascript API - window.open not working from Outlook 2016 Desktop/Windows
问题描述
我有一个用新的JavaScript API编写的Office加载项,其中有一个JS函数,该函数经过一些逻辑后便会使用window.open(url, '_blank')
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')
当在localhost
托管加载项中的Outlook Web的加载项窗格中以及在heroku上部署后,都可以使用它.
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.
但是,当从命令(功能区上的加载项按钮)调用该加载项时,该加载项仅在主机托管在localhost上时有效,当我将其部署在heroku上后,在功能区中显示命令,执行JS逻辑,但是window.open
不执行任何操作.
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.
看起来,打开新窗口的唯一方法是使用Office.context.ui.displayDialogAsync
,但即使这样,它也只能在页面与加载项源于同一来源时起作用.
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.
我认为存在一些安全限制,但是为什么将其托管在localhost上时又可以工作呢?有什么方法可以使用新的Javascript API在Outlook中的命令中打开浏览器窗口吗?
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?
推荐答案
我的经验是,window.open
在不同平台上并非始终可靠,这迫使您使用Office.context.ui.displayDialogAsync
.如前所述,如果您尝试打开不在您的域中的页面,就会大惊小怪.我发现有几种方法可以解决此问题,具体取决于您的使用场景:
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:
- 您可以更新清单的
<AppDomains>
部分,以包括要打开窗口的站点.此部分是一种白名单. - 您可以指向您域中的一个页面,该页面的主要目的是将您重定向到其他地方.我没有遇到重定向窗口的限制,只是打开了它.我将这种方法与qstring参数一起使用,以根据需要控制重定向.
- 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. - 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.
这篇关于Outlook Javascript API-window.open在Outlook 2016桌面/Windows中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!