Office.js使浏览器历史记录功能无效,破坏了历史记录的使用 [英] Office.js nullifies browser history functions breaking history usage

查看:95
本文介绍了Office.js使浏览器历史记录功能无效,破坏了历史记录的使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处提供了office.js的正式版本:

The official version of office.js available here:

https://appsforoffice.microsoft.com/lib/1/hosted/office.js

它在代码中包含以下几行:

It contains the following lines in code:

window.history.replaceState = null;
window.history.pushState = null;

这破坏了我的Excel加载项中的某些历史记录功能(我正在使用reactreact-router)

This breaks some of the history functionality in my Excel Add-ins (I'm using react and react-router)

为什么office.js会取消这些历史记录功能?我在文档中找不到任何解释.

Why is office.js nullifying those history functions? I cannot find any explanation in the documentation.

推荐答案

这对我有用-在office-js删除对象之前先对其进行缓存:

This works for me - cache the objects before office-js deletes them:

<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>

这篇关于Office.js使浏览器历史记录功能无效,破坏了历史记录的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆