Reputation: 1541
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
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
Reputation: 11
Try this
var resizeEvent = window.document.createEvent('UIEvents');
resizeEvent .initUIEvent('resize', true, false, window, 0);
window.dispatchEvent(resizeEvent);
Upvotes: 1
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