I have a Firefox extension that changes the content of the page the user is looking at. As part of this process, the extension should trigger a custom event that the extension itself adds to the page source. I am having difficulty passing parameters to this custom event. What am I doing wrong?
The block script is inserted in the head
part of the page:
document.addEventListener("show-my-overlay", EX_ShowOverlay, false, false, true); function EX_ShowOverlay(e) { alert('Parameter: ' + e.index);
Code in extension:
var event = content.document.createEvent("Events"); event.initEvent("show-my-overlay", true, true); event['index'] = 123; content.document.dispatchEvent(event);
The event fires successfully, but e.index
is undefined.
I managed to get it to work by creating an element on the page, and then the event handler found the element and read its attributes, but it did not look elegant. I want to do this without an element.
EDIT:
I also tried to raise an event with CustomEvent
, but it throws an exception in the handler:
var event = new CustomEvent('show-my-overlay', { detail: { index: 123 } }); content.document.dispatchEvent(event); function EX_ShowOverlay(e) { alert('Parameter: ' + e.detail.index);
Access denied
Edgar source share