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.