我创建了一个简单的Office加载项,其中包含没有<AppDomains>
部分的清单。然后我将以下链接添加到加载项.html文件中:
<a href="https://www.tutorialrepublic.com">Test</a>
当我在Office Online或桌面MS Word中加载加载项并单击该链接时,加载框将从www.tutorialrepublic.com加载html。
我原本预计会根据此处的说明阻止此操作:https://docs.microsoft.com/en-us/office/dev/add-ins/develop/add-in-manifests?tabs=tabid-1#specify-domains-you-want-to-open-in-the-add-in-window
任何人都可以解释这种差异吗?我发现我也可以提交一个表单并将window.location.href设置为外部域,并在addin iframe中打开,而不是按预期在单独的窗口中打开。
答案 0 :(得分:1)
OP链接到的文档有误。已更正。现在相关的段落说:
When running in Office Online, your task pane can be navigated to any URL. However, in desktop platforms, if your add-in tries to go to a URL in a domain other than the domain that hosts the start page (as specified in the SourceLocation element of the manifest file), that URL opens in a new browser window outside the add-in pane of the Office host application.
To override this (desktop Office) behavior, specify each domain you want to open in the add-in window in the list of domains specified in the AppDomains element of the manifest file. If the add-in tries to go to a URL in a domain that is in the list, then it opens in the task pane in both desktop Office and Office Online. If it tries to go to a URL that isn't in the list, then, in desktop Office, that URL opens in a new browser window (outside the add-in pane).
Note
This behavior applies only to the root pane of the add-in. If there is an iframe embedded in the add-in page, the iframe can be directed to any URL regardless of whether it is listed in AppDomains, even in desktop Office.