I'm trying to make a word add in that first must redirect to a login page after initially loading and after logging in redirects back to the add in. The add in is hosted on its own web server. However, after the redirect, I get an error that "Word is undefined". The add in is running inside of word, and I have calls to Office.initialize and Word.run. If I run the add in so that it points back to localhost, instead of the web server for the add in, it runs fine, but when it runs from the web server I get the errors.
Here is what my code looks like for the page that gets the error:
(function () {
"use strict";
Office.initialize = function (reason) {
$(document).ready(function () {
try {
doSomethingInWord();
} catch (e) {
console.log(e);
}
}
}
})();
My "doSomethingInWord" function looks like this:
function doSomethingInWord() {
Word.run(function (context) {
var body = context.document.body;
return context.sync()
.then(function () {
body.clear();
return context.sync().then(function () {
console.log('Did Something in word');
})
}).catch(errorHandler);
}
}