Uncaught TypeError: window.external.GetContext is not a function
Asked Answered
M

4

14

I have created an angular app and wanted to use JS API library into it. I want to use this app inside Office 365 Outlook. However, I am getting the following error:

Uncaught TypeError: window.external.GetContext is not a function
OSF.InitializationHelper.getAppContext  @   o15apptofilemappingtable.js:11

I am running the index.html on a browser and eventually I will run it from inside office 365 outlook. Below is the code:

index.html:

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Office 365 APIs sample</title>
    <base href="/">

    ...
    ...

    <!-- JavaScript Office API -->
    <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js" type="text/javascript"></script>

    <!-- App code. -->
    <script src="scripts/app.js"></script>
    <script src="controllers/homeController.js"></script>

  </head>
<body>
</body>
</html>

app.js:

(function () {     
      console.log("STARTING...");
      var init = function (reason) {
            $(document).ready(function () {
                console.log("ready");
            });
        };

      try {
          Office.initialize = init; 
          if(!window.external.GetContext) {
              console.log('Not in office context');
              init();
          }
      } catch(e) {
          // when in office context unable to access external
          console.log(e);
      }
    });

Please let me know if anyone has encountered this error. I could not find any solution to it by searching on the web.

Thanks!

Megaera answered 21/8, 2015 at 21:49 Comment(3)
Even I encounter the same issue but my suggestion is not to use this approach I mean it is not good to check window.external.GetContext. I don't have any solution right-now but hopping this question would get answered with some valid suggestion.Oraleeoralia
Get the same issue here when running a Yeoman generated app in the browser. What's odd: when you open up the hosted o15apptofilemappingtable.js file, it says: "Excel specific API library". Euhm? In Outlook? Weird.Hereinbefore
How did you solve the problem?Krasner
H
7

I think the problem is that you are opening it in browser window, not inside Office app. I encountered the same problem with Excel add-in. The api should not work properly outside of Office applications. If you need your application to work outside of Excel - you can check if the web-page is opened inside Office application, and only in that case load office api.

Heigho answered 18/11, 2015 at 22:29 Comment(0)
V
2

I have faced the same issue when running the code from browser. The issue got fixed by running the code in MS Outlook mail client with proper manifest XML file.

Vengeful answered 17/9, 2016 at 13:15 Comment(0)
G
1

your app should be inside the office 365 .otherwise it doesn't recognize Office.initialize event. here is how initiation start

Office.initialize = function (reason) {
        $(document).ready(function () {        
                app.initialize();
                // app begin here

        });
};

it looks like your one is angular app. therefore app need to manual bootstrap when Office.initialize fire

Glume answered 21/4, 2016 at 12:47 Comment(0)
A
-1

I encountered the same issue. spend an hour or two. I managed to resolve by deleting local files from directory and took the latest version from source control. Which did restore office.d.ts file and that did the trick for me

Altair answered 21/10, 2015 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.