JJJCoder
JJJCoder

Reputation: 16936

Office Addin - How to tell if loaded in web client or native

I'm working on an Office Add-In and need to be able to tell if the document was loaded in the standard Office software or Office365 Online.

I've checked the docs and can't find anything.

In office.js, there is an enumeration that looks as if it should be used somewhere, but i can't tell what property/event notifies us of the type. I have also stuck a breakpoint on the Office object and can't see anything.

Microsoft.Office.WebExtension.ApplicationMode={
WebEditor: "webEditor",
WebViewer: "webViewer",
Client: "client"
};

Does anyone know how to do this please?

Upvotes: 3

Views: 2059

Answers (3)

radiovisual
radiovisual

Reputation: 6468

I know this question was asked a long time ago, but it was something I was also looking for, and then stumbled upon the Office.context object, which gives me all the information I need about the hosting platform of the Office Add-in.

Some examples to follow...

Calling Office.context on macOS, via Outlook Desktop:

{
  contentLanguage: "en-US"
  diagnostics: {
     host: "Outlook", 
     version: "16.47.314.0",
     platform: "Mac"
  },
  displayLanguage: "en-US",
  host: "Outlook",
  isDialog: false,
  platform: "Mac"
}

Calling Office.context on macOS, via Outlook Web:

{
  contentLanguage: "",
  diagnostics: {
    host: "Outlook",
    platform: "OfficeOnline",
    version: "0.0.0.0"
  },
  displayLanguage: "en-US",
  host: "Outlook",
  isDialog: false,
  platform: "OfficeOnline"
}

So looking at the platform value is probably the most useful in your situation, where you can learn if this Add-in is being accessed via the web, mobile, desktop, etc.


All of the possible platform values can be found here: https://learn.microsoft.com/en-us/javascript/api/office/office.platformtype?view=excel-js-preview

The documentation for Office.context Interface can be found here: https://learn.microsoft.com/en-us/javascript/api/office/office.context?view=excel-js-preview#platform

Upvotes: 5

Jerry Weeks
Jerry Weeks

Reputation: 315

Searching for the same, but in my case for Word not Outlook, I just discovered that this code

        showNotification("url is: " + Office.context.document.url);

gives a URL something like this, in my case

        url is: https://<corp portal name>-my.sharepoint.com/personal/<my name>/Documents/Document15.docx

the number 15 is due to the fact I am currently up to 15 in-named documents in my OneDrive for Business folder (which is where these end up)

On a local client version of Word URL is blank.

Upvotes: 0

Tim Wan
Tim Wan

Reputation: 155

For reference, in Outlook you can use this to tell the difference between OWA or desktop or mac Outlook:

https://dev.outlook.com/reference/add-ins/Office.context.mailbox.diagnostics.html

Upvotes: 2

Related Questions