javascript - Manually trigger an event on window object -


i adding listener so:

    window.addeventlistener('native.showkeyboard', function (e) {         ...         ...     }); 

i'm writing unit test want trigger event. im doing:

    window.trigger('native.showkeyboard'); 

but end error line saying:

    undefined not function 

how can manually trigger event?

edit

i have tried:

  $(window).trigger('native.showkeyboard'); 

but handler doesnt run it's not registered jquery...

if triggering event via jquery event ought have been attached via jquery -- see @frederichamidi's comment.

$(window).on('native.showkeyboard', function (e) {     ......... });  $(window).trigger('native.showkeyboard'); 

working jsfiddle demo

or if you're using plain vanilla js way:

window.addeventlistener('native.showkeyboard', function (e) {     ........ });  window.dispatchevent( new event('native.showkeyboard') ); 

working jsfiddle demo


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -