Custom events and the window object

Added by Eric van der Vlist almost 5 years ago

In JavaScript custom events are as simple as:

window.addEventListener('AnEvent', function(){alert('AnEvent');}, false); window.dispatchEvent(new CustomEvent('AnEvent'));

With Saxon CE, I had assumed that you could do something similar:

HTML: Hello World for Saxon CE

XSLT: <?xml version="1.0" encoding="UTF-8"?>

<xsl:template name="init">
    <ixsl:set-property name="dummy"
        select="ixsl:eval(&quot;window.dispatchEvent(new CustomEvent('AnEvent'))&quot;)"/>

<xsl:template match="ixsl:window()" mode="ixsl:onAnEvent">
    <xsl:result-document href="#output">
        <p>Got it!</p>


I have tested this with Firefox and Chromium and the second template is not activated in both cases.

Using JS developer tools I can see that an event handler has been installed:

window.onAnEvent function (){try{var b;var c=arguments,d;var e;0!=s3&&(e=j3(),2E3

But manually running "window.dispatchEvent(new CustomEvent('AnEvent'))" returns true and does not run the template.

Manually running "window.onAnEvent(new CustomEvent('AnEvent'))" does execute the template!

Have I missed something or is there something wrong with the way the handler is registered?



Please register to reply