Project

Profile

Help

Custom events and the window object

Added by Eric van der Vlist about 11 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:


    
        <title>Hello World for Saxon CE</title>
        <script type="text/javascript" language="javascript" src="saxon/SaxonceDebug/Saxonce.nocache.js"></script>
    <script type="application/xslt+xml" language="xslt2.0" src="repro-event.xsl" data-initial-template="init"></script>
</head>
<body>
    <div id="output"> </div>
</body>

XSLT:




    
        
    

    
        
            

Got it!

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?

Thanks,

Eric


Please register to reply