无法在 Mail Addin 中使用 window.history.replaceState 函数

2024-01-05

我使用 durandal 框架和 Office365 JavaScript API(office.js) 创建了 Outlook365 的 SPA 邮件插件。在我的应用程序中我想使用的某个地方window.history.replaceState函数,但该函数在 office.js 中显式设置为 null 导致错误。

//following lines are presents in Office.js
window.history.replaceState = null;
window.history.pushState = null;

我找到了一个简单的解决方案,react-router此更改后工作正常。我们可以备份之前的功能Office.js使它们无效index.html,然后恢复:

<script>
  window.backupHistoryFunctions = {};
  window.backupHistoryFunctions.pushState = window.history.pushState;
  window.backupHistoryFunctions.replaceState = window.history.replaceState;
</script>
<!-- Office JavaScript API -->
<script type="text/javascript" src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js">
</script>
<script>      
  window.history.pushState = window.backupHistoryFunctions.pushState;
  window.history.replaceState = window.backupHistoryFunctions.replaceState;
  console.log(window.history.replaceState)
</script>

正如微软代表所指出的,这与 Excel 不兼容,但我想这对于邮件插件来说应该没问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Mail Addin 中使用 window.history.replaceState 函数 的相关文章

随机推荐