加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

office365 – 未捕获TypeError:window.external.GetContext不是

发布时间:2020-12-13 20:14:02 所属栏目:Windows 来源:网络整理
导读:我已经创建了一个有角度的应用程序,并希望使用 JS API库.我想在Office 365 Outlook中使用这个程序.但是,我收到以下错误: Uncaught TypeError: window.external.GetContext is not a functionOSF.InitializationHelper.getAppContext @ o15apptofilemappingt
我已经创建了一个有角度的应用程序,并希望使用 JS API库.我想在Office 365 Outlook中使用这个程序.但是,我收到以下错误:
Uncaught TypeError: window.external.GetContext is not a function
OSF.InitializationHelper.getAppContext  @   o15apptofilemappingtable.js:11

我在浏览器上运行index.html,最后我将从办公室365外观中运行它.以下是代码:

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);
      }
    });

如果有人遇到这个错误,请通知我.我在网上搜索找不到任何解决方案.

谢谢!

我认为问题是你在浏览器窗口打开它,而不是在Office应用程序中.我遇到与Excel加载项相同的问题. api不能在Office应用程序之外正常工作.如果您需要您的应用程序在Excel之外工作 – 您可以检查是否在Office应用程序中打开网页,只有在这种情况下才能加载office api.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读