Naju
Naju

Reputation: 1541

Window resize trigger event is not working in IE11

I want to call the resize event using code.

I am using following code .It is working fine in otherbrowsers but not in the IE11.

if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
            $(window).trigger('resize');

        } else {
            window.dispatchEvent(new Event('resize'));

        }

Please advice me, am I missing anything?

Upvotes: 10

Views: 11145

Answers (3)

saddy
saddy

Reputation: 11

The solution from the other post How to trigger the window resize event in JavaScript? that I came across works well.

Snippet of the same:

if (typeof(Event) === 'function') {
    // modern browsers
     window.dispatchEvent(new Event('resize'));
} else {
    // for IE and other old browsers
    // causes deprecation warning on modern browsers
    var evt = window.document.createEvent('UIEvents'); 
    evt.initUIEvent('resize', true, false, window, 0); 
    window.dispatchEvent(evt);
}

Upvotes: 1

teacoffee
teacoffee

Reputation: 11

Try this

var resizeEvent = window.document.createEvent('UIEvents'); 
resizeEvent .initUIEvent('resize', true, false, window, 0); 
window.dispatchEvent(resizeEvent);

Upvotes: 1

Shivek Parmar
Shivek Parmar

Reputation: 2993

Even Internet explorer 11 does not support resize event. Therefore, I have resolved this by using following solution.

if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
     var evt = document.createEvent('UIEvents');
     evt.initUIEvent('resize', true, false, window, 0);
     window.dispatchEvent(evt);
    } else {
       window.dispatchEvent(new Event('resize'));

    }

Upvotes: 31

Related Questions