In our Dynamics CRM integration, we are loading WebResource, containing JS code. In this code, we create eventListener to get events from an iframe.
Since we need to open side panel (Xrm.Panel.loadPanel) from most of screen in CRM, we've added a button to most of ribbons, that load our web resource and in this web resource we register event listener, like this:
if (!window.top.psdcMessageListener) {
window.top.psdcMessageListener = function(event) {};
window.top.addEventListener('message', window.top.psdcMessageListener, false);
console.log("PSDC: Added event listener");
};
Everything works fine and we receive the event, until we run the code for a second time (e.g. opening account or activity) - now we still have our listener in Global Listeners of Chrome, but now it just doesn't fire at all.
There are other listeners for 'message' event, that are coming with CRM such as Crossdomain.js or sdk.js and they appear in the same list of Global Listeners, and working fine.
Is there any way to fix it / to see why it's not being called? Or alternatively, is there is a way to load web resource globally once per load of Dynamics CRM window?
Thanks.