admin管理员组

文章数量:1289634

Hi I'm using DOM2 and added a few event listeners "resize" for window object, using addEventListener. And now I need to simulate this action (window.resize) to call event listeners that are attached to the window object. How can I do it?

Hi I'm using DOM2 and added a few event listeners "resize" for window object, using addEventListener. And now I need to simulate this action (window.resize) to call event listeners that are attached to the window object. How can I do it?

Share Improve this question asked Mar 8, 2015 at 13:22 SimchaSimcha 3,4007 gold badges30 silver badges44 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

The following should work:

var resizeEvent = new Event('resize');

window.dispatchEvent(resizeEvent);

Simple (ridiculously so) demo.

References:

  • Creating and triggering (JavaScript) events.
  • Event() constructor.

本文标签: javascriptSimulate event resizeStack Overflow