Spa*_*tan 14 office365 office365-apps office-js
我创建了一个角度应用程序,并希望使用JS API库.我想在Office 365 Outlook中使用此应用程序.但是,我收到以下错误:
Uncaught TypeError: window.external.GetContext is not a function
OSF.InitializationHelper.getAppContext @ o15apptofilemappingtable.js:11
Run Code Online (Sandbox Code Playgroud)
我在浏览器上运行index.html,最终我将从Office 365 outlook中运行它.以下是代码:
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>
Run Code Online (Sandbox Code Playgroud)
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);
}
});
Run Code Online (Sandbox Code Playgroud)
如果有人遇到此错误,请告诉我.我在网上搜索找不到任何解决方案.
谢谢!
小智 7
我认为问题在于您是在浏览器窗口中打开它,而不是在Office应用程序中打开它.我在使用Excel加载项时遇到了同样的问题.api在Office应用程序之外不能正常工作.如果您需要您的应用程序在Excel之外工作 - 您可以检查Web页面是否在Office应用程序中打开,并且仅在这种情况下加载office api.
| 归档时间: |
|
| 查看次数: |
1995 次 |
| 最近记录: |