2

So I added a little bit of jQuery and now IE crashes pretty hard when I try to load my page. Other browsers seem fine. IE behaves much in the same manner as when I've accidentally created an infinite loop in the past, but since it's not causing problems for other browsers I'm a little confused as to what the actual cause is.

$(window).resize(function(){
sizeOfResize = $('#main').width()*.9;
$('#news p').width(sizeOfResize);   
})
aslum
  • 11,774
  • 16
  • 49
  • 70
  • 3
    Did you try to round up sizeOfResize? IE might not like the decimals for sizes? – jValdron Jan 05 '12 at 17:58
  • 1
    setting `width()` probably recalls another `resize` event--infinite loop. – Brad Christie Jan 05 '12 at 17:58
  • @BradChristie -- I thought that too, but the resize callback is on `window`, so a resize on a child shouldn't trigger it again. –  Jan 05 '12 at 17:59
  • @cwolves: touche, with the exception of maybe margins. – Brad Christie Jan 05 '12 at 18:00
  • @jValdron That's not it... I just tried `sizeOfResize = Math.floor($('#main').width()*.9);` with similar results. Thanks for the reminder though, as I had just left the "rounding" out in this iteration of the script. – aslum Jan 05 '12 at 18:03
  • @kichik Actually it is my last mistake... I got the code working in every other browser before I bothered checking IE. (; – aslum Jan 05 '12 at 18:08

2 Answers2

3

2 things I noticed - which may or may not be the case. As we all commented, IE gets angry without you having to do much.

Anyways, to the point. In your example code, you don't have a semi-colon at the end of the function. I don't know if that would cause IE to be angry or not, but it's worth a try. IE is very touchy about commas and semi-colons and not in the least forgiving like the other browsers.

If the above doesn't work, see if it will take a number other than .9 - maybe try a whole number. I'm thinking it may not like the . in the .9 - if that's the case, you'll have to change how you do the math.

Francis Lewis
  • 8,872
  • 9
  • 55
  • 65
1

Not a direct answer, but usually the way I test my code is to start with simple alerts and get more complex. for example, try starting with this code:

$(window).resize(function(){
     alert("TEST");   
})

If that doesn't break it, then add the next part of your original sample:

 $(window).resize(function(){
sizeOfResize = $('#main').width()*.9;
alert("TEST");   
})

And if that doesn't break it, add the last bit:

$(window).resize(function(){
sizeOfResize = $('#main').width()*.9;
$('#news p').width(sizeOfResize);  
   alert("test"); 
})

This won't fix your problem, but it should point to the specific line of code that is breaking it.

Here is a similar question and answer as well:

Cross-browser window resize event - JavaScript / jQuery

Hope that helps

Community
  • 1
  • 1
Nick
  • 1,262
  • 1
  • 17
  • 32