Trigger window.resize event via javascript

2016-06-15

Use below code to trigger window.resize event.

This can be helpful to refresh some libraries like Chartist.js when a panel  or a div the control is contained in is expanded.


window.dispatchEvent(new Event('resize'));

P.S.

The above method isn’t supported by Internet explorer (failed on IE 11), therefore use below method for wider browser support.


    var fireRefreshEventOnWindow = function () {
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent('resize', true, false);
        window.dispatchEvent(evt);
    };

   // call the fireRefreshEventOnWindow(); function to fire refresh event.
   // ...
This entry was posted in Javascript and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *