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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: