Why does IE8 hangs on jquery window.resize event?

12,026

If "show window contents while dragging" is switched on, you will be inundated with resize events. I guess you're testing IE8 on a separate Windows machine which has this effect enabled (Display Properties -> Appearance -> Effects...).

To counteract this, you can wrap & trap the resize events to tame them: http://paulirish.com/demo/resize

This article says Chrome, Safari & Opera suffer from this too.

Share:
12,026
Vasile Tomoiaga
Author by

Vasile Tomoiaga

Project Manager, Romania

Updated on June 18, 2022

Comments

  • Vasile Tomoiaga
    Vasile Tomoiaga almost 2 years

    I discovered a problem that seems to reproduce always when opening a piece of html and javascript in IE8.

    <html>
        <body>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $(window).resize(function() {
                    console.log('Handler for .resize() called');
                });
            });
        </script>
        <div id="log">
        </div>
        </body>
    </html>
    

    Loading this file in IE8 and opening Developer Tools will show that the log message is printed continuously after one resize of the browser window.

    Does anyone has an idea why? This is not happening in IE7 or IE9, nor in other browsers (or at least their latest versions).

    UPDATE

    One solution to prevent the continuos trigger of resize() is to add handler on document.body.onresize if the browser is IE8.

     var ieVersion = getInternetExplorerVersion();
        if (ieVersion == 8) {
            document.body.onresize = function () {
            };
        }
        else {
            $(window).resize(function () {
            });
        }
    

    But this does not answer my question: is the continuous firing of resize() a bug in IE8?

    • DanielB
      DanielB almost 13 years
      Could not reproduce this issue in IE8 with this fiddel: jsfiddle.net/hrtp8