javascript - office-js: Uncaught TypeError: window.external.GetContext is not a function -


i'm struggeling check if hosted web application opened browser or in outlook 2013/2016 client.

this approach:

/**  * check if app running in outlook  */ $rootscope.isoutlook = false; $(document).ready(function () {     try {         office.initialize = function() {             var hosttype = office.context.mailbox.diagnostics.hostname;             if (hosttype === "outlook" || hosttype === "mac outlook" || hosttype === "outlookwebapp") {                 $rootscope.isoutlook = true;             }         };     } catch (e) {         if (e instanceof typeerror) {             // catch error if web app opened in browser.             console.log('not in office context! generated error: ' + e);         }     } }); $log.debug('isoutlook: ' + $rootscope.isoutlook); 

the function works charm, can't rid of 'uncaught typeerror'. keeps throwing me uncaught typeerror in console of browser:

uncaught typeerror: window.external.getcontext not function 

office.context.mailbox.diagnostics.hostname telling type of office host have. seems maybe trying run same app both inside of office host , standalone web page.

there post simon j.k. pedersen scenario, involves checking if same window.external.getcontext function exists. not documented.

 office.initialize = init;  try {      if (!window.external.getcontext) {          $rootscope.isoutlook = false;          init(); // manually call init      }  } catch (e) {      // when in office context unable access external.  } 

you include query string parameter in office manifest , check know it's coming office.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -