Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
57
rated 0 times [  64] [ 7]  / answers: 1 / hits: 22093  / 13 Years ago, mon, april 4, 2011, 12:00:00

I just noticed that the jquery resize event fires twice any time the browser window is resized. I'm unable to find any documentation listing this as the default behavior. I have tested this in the latest versions of Chrome and Firefox, using jQuery 1.4 and 1.5.



Does anyone else see this behavior? Is there a specific reason for it?



Update: This happens if I click the maximize button on the browser window once. I understand that if I'm manually dragging the window to a different size, the event will be fired multiple times, but that shouldn't be the case with the maximize button.



The code used test this is below. The browser resized text is output twice:



<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
http://www.w3.org/TR/html4/loose.dtd>
<html>
<head>
<title></title>
</head>
<script src=//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js></script>
<script type=text/javascript>
$(window).resize(function(){
console.log('Browser Resized');
});
</script>
<body>

</body>
</html>

More From » jquery

 Answers
13

This is not a problem of jQuery. It depends on the browser implementation. The browser decides when to trigger 'resize'. And you can use window.onresize = function() {...} to test. It will be same. Nothing to do with jQuery. I tested on Win7 chrome, it is fired twice, and in Win7 opera/safari it's fired once.


[#92921] Saturday, April 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
richardaydenc

Total Points: 148
Total Questions: 125
Total Answers: 98

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
richardaydenc questions
Fri, Dec 4, 20, 00:00, 4 Years ago
Thu, Jul 2, 20, 00:00, 4 Years ago
;