Posted inJavaScript / jQuery

window.resize javascript – How to Capture Browser Window Resize Event in JavaScript?

window.resize javascript To add a resize event to the window, we can use the onresize() function in JavaScript.

window.resize javascript

you can trigger the resize event using window.dispatchEvent() method: Alternatively, you can use the window.resizeTo() to trigger the resize event. In jQuery, you can trigger the window resize event using the .trigger() method.

JavaScript window resize event

window.addEventListener('resize', function(event) {
    ...
}, true);

//OR

window.onresize = function(event) {
    ...
};

use the window.resizeTo() to trigger the resize event.

window.addEventListener("load", function() {
    window.resizeTo(
        window.screen.availWidth / 2,
        window.screen.availHeight / 2
    );
});
 
window.onresize = function() {
    alert('Handler for .resize() called!');
}

How to Capture Browser Window Resize Event in JavaScript

Use the addEventListener() Method





JavaScript Window Resize Event - www.pakainfo.com


Note: Please resize the browser window to see how it works.

Trigger window’s resize event with JavaScript/jQuery

$(document).ready(function() {
    $(window).trigger('resize');
});
 
$(window).resize(function() {
    alert('Handler for .resize() called!');
});
Edit in JSFiddle


Don’t Miss : Browser Window Resize Function With AngularJS

I hope you get an idea about window.resize javascript.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this Article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype