office.js的官方版本可在此处获得:
https://appsforoffice.microsoft.com/lib/1/hosted/office.js
Run Code Online (Sandbox Code Playgroud)
它在代码中包含以下行:
window.history.replaceState = null;
window.history.pushState = null;
Run Code Online (Sandbox Code Playgroud)
这打破了我的Excel加载项中的一些历史功能(我正在使用react和react-router)
为什么office.js会使这些历史记录功能无效?我在文档中找不到任何解释.
小智 7
Excel中使用的浏览器控件不支持History API,如果未对replaceState和pushState进行排序,则它们可以作出反应但在调用时始终抛出异常.在新的浏览器控件可用之前,您需要切换到基于散列的路由或使用填充历史API.如果在office.js之后包含脚本引用,https://github.com/devote/HTML5-History-API似乎有效.
小智 6
这对我有用-在office-js删除对象之前先缓存它们:
<script type="text/javascript">
// Office js deletes window.history.pushState and window.history.replaceState. Cache them and restore them
window._historyCache = {
replaceState: window.history.replaceState,
pushState: window.history.pushState
};
</script>
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script type="text/javascript">
// Office js deletes window.history.pushState and window.history.replaceState. Restore them
window.history.replaceState = window._historyCache.replaceState;
window.history.pushState = window._historyCache.pushState;
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1537 次 |
| 最近记录: |