【问题标题】:Conflict of displayDialogAsync and html5-history-apidisplayDialogAsync 和 html5-history-api 的冲突
【发布时间】:2017-09-16 00:21:48
【问题描述】:

我有一个mean-stack 的应用程序,它托管了一个网站和一个 Excel 加载项。 html5 已启用,并且有

<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>
<script src="https://cdn.rawgit.com/devote/HTML5-History-API/master/history.js"></script>

在 Excel 加载项中,我有一个按钮,可以通过Dialog API 在网站中打开一个页面:

$scope.openDialog = function () {
  Office.context.ui.displayDialogAsync("https://localhost:3000/preview/tmp/6wr-4PqdBrYQwjp3AAAD", {}, function () {})   
}

当我在Chrome中的Excel Online中单击此按钮时,它会打开一个带有以下url的对话框(注意#和几个%2F被系统地附加了),但这并不妨碍很好地显示页面.

https://localhost:3000/preview/tmp/6wr-4PqdBrYQwjp3AAAD?_host_Info=excel|web|16.00|en-us|b6f37f78-e519-7d03-0069-b9c4317a362c|isDialog#%2Fpreview%2Ftmp%2F6wr-4PqdBrYQwjp3AAAD%3F_host_Info=excel%7Cweb%7C16.00%7Cen-us%7Cb6f37f78-e519-7d03-0069-b9c4317a362c%7CisDialog

但是,当我在 Firefox 中单击 Excel Online 中的此按钮时,url 很快变为以下 url,结果显示该网站的主页:

https://localhost:3000/home#%2Fpreview%2Ftmp%2F6wr-4PqdBrYQwjp3AAAD%3F_host_Info=excel%7Cweb%7C16.00%7Cen-gb%7C919fff78-e51f-dc20-0c3c-871b7d0ec25d%7CisDialog

所以我的问题是:

1) 为什么Office.context.ui.displayDialogAsync会在我的网站url中系统地添加#%2F?是否有可能防止这种情况发生?

2) 是否可以制作一个 Firefox 接受的 url(不管 #%2F)?

编辑1:看来如果我不使用html5-history-api,它会起作用。所以不知道如何为那个displayDialogAsync禁用html5-history-api? (在office.js之后我必须使用html5-history-api的原因是here。)

【问题讨论】:

  • 您能否分享一个链接,供人们测试您所描述的行为?
  • @VivekAthalye 抱歉,目前我没有其他托管平均堆栈应用程序的 SSL 域名...

标签: html ms-office office-js html5-history fragment-identifier


【解决方案1】:

不是displayDialogAsync 这样做的。这是 Angular 路由和 Angular 定位策略的常见问题。搜索“angular app is added hash to my urls”,你会发现很多关于它的信息和解决方案。

【讨论】:

  • 我可以在浏览器中很好地打开https://localhost:3000/preview/tmp/6wr-4PqdBrYQwjp3AAAD,是displayDialogAsync加了hash...
  • 我不同意。这不是 Office.js 中向 URL 添加哈希值的代码。但是当您使用某些位置策略时,Angular 中就有。请按照我的建议进行搜索。您会发现它不会发生在每个 URL 上。这是一个复杂的现象。
  • 我昨天编辑了OP...我的测试表明如果我删除html5-history-api,则不会添加哈希,因此displayDialogAsynchtml5-history-api之间存在冲突。但是由于this,我必须在整个应用程序中使用html5-history-api
猜你喜欢
  • 2013-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-01
  • 2013-01-26
  • 1970-01-01
  • 2014-09-28
  • 2017-12-12
相关资源
最近更新 更多