Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore errors and continue running javascript in IE?

I've got a JIT Spacetree on my webpage, and IE doesn't like a few lines. If I open the developer tools, and tell it to run through them, it looks great and loads everything as it should.

Is there any way I can get it to just say "You know what, these errors aren't really deal breakers, let's keep on going here"? The two further indented lines are the offenders, as well as something in jQuery 1.6.4 (will be trying 1.7.1) with either $.getJSON or $.parseJSON

    var style = label.style;
        style.width = node.data.offsetWidth;
        style.height = node.data.offsetHeight;            
    style.cursor = 'pointer';
    style.color = '#fff';
    style.fontSize = '0.8em';
    style.textAlign= 'center';
},
like image 983
Rob Avatar asked Feb 22 '12 15:02

Rob


3 Answers

wrap the offending code in a try/catch, and don't do anything in the catch.

like image 171
DaveS Avatar answered Sep 28 '22 10:09

DaveS


IE is "allergic" in defining an object and leave a comma at the last attribute.

Bad:

var apple = { color : "yellow",
              taste : "good", };

Good:

var apple = { color : "yellow",
              taste : "good" };
like image 41
p1100i Avatar answered Sep 28 '22 10:09

p1100i


You could use a try catch statement.

var style = label.style;

try 
{
    style.width = node.data.offsetWidth;
    style.height = node.data.offsetHeight;            
} 
catch(err) { /* do nothing */ }

style.cursor = 'pointer';
style.color = '#fff';
style.fontSize = '0.8em';
style.textAlign= 'center';
like image 39
Micah Avatar answered Sep 28 '22 12:09

Micah