I am attempting to simulate a resize event using vanilla JavaScript for testing purposes, but it seems that modern browsers prevent the triggering of the event with window.resizeTo()
and window.resizeBy()
. I also tried using jQuery $(window).trigger('resize');
, but it only works for events that are attached using jQuery, like $(window).on('resize', handler);
. Unfortunately, the project I am currently working on requires plain JavaScript.
Here is an example:
window.addEventListener('resize', function(){
console.log('Window has been resized!');
});
// Alternatively, you can use global onresize
window.onresize = function() {
console.log('Window has been resized!');
};