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

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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: