Trigger window.resize event via javascript


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'));


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);

   // 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 *