I'm writing an Office Add-in (formerly, Apps for Office). I'm using office.js
and in some point of code I want to check if the app is running in excel (desktop software) or running on the web (Excel Online)
Something like:
if (Office.IsRunningOnWeb){
// Do something.
}
@Mehrandvd, if I may ask, what do you need this distinction for (e.g,. what would you do different based on knowing that you're in Excel Online vs. the Desktop)? I work on the Office.js APIs, so I'm happy to channel your feedback to my team, if you can provide some specifics.
If you need this distinction for feature detection, I would recommend checking the API Requirement sets instead, via a new (but back-ported to all endpoints) API,
Office.context.requirements.isSetSupported(name, version)
. Please see my answer at Neat ways to get environment (i.e. Office version).If it's due to some API differences you're seeing between the Excel desktop vs Online versions, the goal is for the APIs to behave the same across endpoints, so it may be a bug. If you let me know the specifics, I can follow up.
Re. the answer mentioned by @Afshin -- it may work, but just be aware that it's not public API but rather the internal workings that you're testing against, so there's a chance that this approach would stop working in the future... The only publically-exposed namespace is
Office
(and, with the new Excel and Word APIs released in Sept. 2015, alsoExcel
andWord
andOfficeExtension
).Hope this helps!
~ Michael Zlatkovsky
Developer on Office Extensibility team, MSFT
PS: Please use the
office-js
tag for tagging these sorts of questions in the future; this is the stackoverflow tag that the Office Extensibility team at Microsoft actively looks at.You can use document type:
The question is how do you do it, not why would you want to. There are numerous reasons why you might want to differentiate. Put in this check as follows: