如何取消Office Online调用displayDialogAsync时的新窗口权限提示?
Ah, I’ve dealt with this exact permission prompt headache in Office Online before—total buzzkill for user experience! The good news is there’s a reliable way to make that "wants to display a new window" notification disappear entirely. Let’s break down the steps:
First, quick context: that prompt pops up because Office Online is wary of untrusted domains trying to open new windows. To bypass it, we need to tell Office our dialog is trusted and render it inline instead of as a separate window.
Whitelist your dialog’s domain in the add-in manifest
Before anything else, make sure the domain hosting your dialog page is added to theAppDomainssection of your Office Add-in manifest. This is Office’s way of verifying the dialog source is safe. For example:<AppDomains> <AppDomain>https://your-addin-domain.com</AppDomain> </AppDomains>Double-check the domain matches exactly (no extra slashes, correct HTTPS protocol—Office requires HTTPS for all add-in content).
Enable inline rendering with
displayInIframe
The magic setting here isdisplayInIframein yourdisplayDialogAsyncoptions. When set totrue, Office Online renders the dialog inside an iframe within the current Office window instead of trying to spawn a new browser window—this skips the permission request entirely. Here’s how to implement it:function openCustomDialog() { const dialogSettings = { displayInIframe: true, width: 65, // Width as percentage of the parent window height: 55, title: "Your Dialog Title" // Replace with your desired title }; Office.context.ui.displayDialogAsync( "https://your-addin-domain.com/your-dialog-page.html", dialogSettings, (asyncResult) => { if (asyncResult.status === Office.AsyncResultStatus.Succeeded) { const dialog = asyncResult.value; // Optional: Set up event handlers for dialog interactions dialog.addEventHandler(Office.EventType.DialogClosed, onDialogClosed); } else { console.error("Failed to open dialog: ", asyncResult.error.message); } } ); }Key things to remember
displayInIframeonly works in Office Online (web clients). Desktop Office apps ignore this setting, but they don’t show that permission prompt anyway—they use native system dialogs by default.- Your dialog page must be served over HTTPS (non-negotiable for Office Online add-ins).
- If the prompt still appears, double-check your
AppDomainsentry—even a tiny typo can break the trust relationship.
内容的提问来源于stack exchange,提问作者Daniel A. White

