Search code examples
office-jsappdomainoutlook-web-addins

Outlook client add-ins: links and JS redirects to other domain, open a new browser tab


My site is domaina.com. when i execute this code on Microsoft Edge DevTools Preview:

location.href = domainb.com/xxx/xxx

it can't redirect to the domainb.com on the right site add-on panel, it open my default browser to load my links.

I have add domainb.com to my manifest like this one:

<AppDomain>https://domainb.com</AppDomain>

when i execute code like below:

var displayUrl = "https://domainb.com";
Office.context.ui.displayDialogAsync(displayUrl, { height: 75, width: 40 }, function(result) {
    console.log('displayDialogAsync: ');
    console.log(result);
});

The Edge DevTools will console log an error result like below:

[object Object]: {error: Object, status: "failed", value: undefined}

error: Object
code: 12004
message: "The domain of the URL is not included in the AppDomains element in the manifest, and is not subdomain of source location."
name: "Display Dialog Error"

__proto__: Object
status: "failed"
value: undefined

__proto__: Object

But in fact, I have add domainb.com to my manifest:

<AppDomains>
<AppDomain>https://domainb.com</AppDomain>
<AppDomains>

But it is useless for

Window 10 1903 Verison OS build: 18362.535
Outlook client: Verison 1911 (Build 12228.20364 Click-to-Run) MSO (16.0.12228.20322) 64Bit.

I think that was caused by Edge engine. https://learn.microsoft.com/en-us/office/dev/add-ins/concepts/browsers-used-by-office-web-add-ins

For more details :https://github.com/OfficeDev/office-js/issues/917


Solution

  • IIRC when zou open the Dialog with displayDialogAsync the url you pass has to be on the localhost (e.g. https://localhost:3000/dialog.html), from there you can redirect to whatever site you have added to <AppDomains>

    <!-- dialog.html -->
    ...
    <script>
    Office.initialize = () => {
      window.location.href = 'https://url_included_in_app_domains' // domainb.com/xxx/xxx
    }
    ...
    </script>