StorageEvent does not work in Excel for Windows

别等时光非礼了梦想. 提交于 2019-12-01 10:49:10

问题


As some existing threads suggest (eg, one, two, three), current Dialog Box does not provide an API to send regularly messages from the host page (eg, task pane) to the Dialog box.

So I have to look for a workaround: we reserve a variable message in localStorage, then we make the Dialog box check regularly if the value of message changes. It is like manually implementing an event listener by localStorage.

Does anyone know how to implement that in a sure and efficient way (given JavaScript isn't a multi-threaded language)? I don't want this listener to be costly, and what would be the appropriate interval to set?

Edit 1:

I tried the StorageEvent that @PatrickEvans suggested. For both the add-in and the dialog site, we need to implement a sendMessage... and a receiveMessage... by the variables messageFromHostToSite and messageFromSiteToHost in storage.

It worked in Excel Online in Chrome, and in Excel Online in IE 11. However, it did NOT work in Excel 2016 for Windows 7 or 10; we can set items to localStorage and get them back, changing localStorage seems to not fire anything.

So could anyone confirm that StorageEvent is indeed not supported in Excel 2016 for Windows 7 or 10? In that case, I am still looking for other workarounds...

Edit 2:

I finally made a simplified example: here is the xml file, which calls the add-in and the site. It works well in Excel Online, but does NOT fire events in Excel for Windows.


回答1:


I had similar issues communicating between apps. In my testing, Excel Online storageEvent works because the communication is between browser tabs of the same "instance". With Excel for Windows, 2 add-ins are in separate browser "instances"; which don't communicate storageEvents. Worse yet was Office for Mac (WebKit); which did not communicate storageEvents and also could not read storage changes from the other app unless they were restarted -- I believe this is because the storage values were cached for the instance (not written to disk and not visible to the other instance/app).

So, I believe Excel Online could use StorageEvents, Excel for Windows would require polling (e.g. check every second), and Excel for Mac may require a server-based solution, such as WebSockets.



来源:https://stackoverflow.com/questions/44541675/storageevent-does-not-work-in-excel-for-windows

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