Cannot load local office.js

混江龙づ霸主 提交于 2019-12-20 04:41:35

问题


As this answer suggested, I want to modify a little bit office.js.

So I copied the content of https://appsforoffice.microsoft.com/lib/1/hosted/office.js to local, such that https://localhost:3000/static/office.js shows well the content.

Then, I make a very simple file test.html:

<html>
    <head>
        <!--<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>-->
        <script type="text/javascript" src="https://localhost:3000/static/office.js"></script>
    </head>
    <body>
        haha
    </body>
</html>

Loading https://localhost:3000/static/test.html with remote office.js in a browser shows Warning: Office.js is loaded outside of Office client o15apptofilemappingtable.js:11, and loading it in an Office add-in works well.

However, loading https://localhost:3000/static/test.html with local office.js in a browser shows Uncaught SyntaxError: Unexpected token < o15apptofilemappingtable.js:1, and loading it in an Office add-in gives an error Add-in Error Something went wrong and we couldn't start this add-in. Please try again later or contact your system administrator.

So does anyone know what's wrong here? Is it possible to make our own local version of office.js?


回答1:


See my answer in the linked question. Essentially, no, you should not be making your own local copy of "office.js". But if you did want a local copy -- which we already offer on NuGet and, more recently, on NPM (https://www.npmjs.com/package/@microsoft/office-js) -- you would need all the associated files in that directory as well, not just Office.js itself.

See https://unpkg.com/@microsoft/office-js@1.1.1/dist/ for a listing of the files and folders that make up Office.js. Not all (in fact, not most) are used in any given session, but you do want the whole set of files since different ones are loaded in different circumstances.



来源:https://stackoverflow.com/questions/44861833/cannot-load-local-office-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!