Ignore errors and continue running javascript in IE?

I have JIT Spacetree on my webpage and IE doesn't like multiple lines. If I open the developer tools and tell them to go through them, it looks great and loads everything that should be.

Is there any way to make him just say, β€œYou know, these errors don't really break the job, go on here”? The other two indentation are offenders, as well as something in jQuery 1.6.4 (will try to use 1.7.1) with $ .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'; }, 
+6
source share
6 answers

wrap the violation code in try / catch and do nothing in catch.

+8
source

IE is "allergic" to the definition of an object and leaves a comma for the last attribute.

Poorly:

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

Good:

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

You can use the 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'; 
+2
source

Wrap this intruder code inside a try { } catch (e) {} and you should be good to go.

MDN reference for try..catch

Something like below should work for you,

 var style = label.style; try { style.width = node.data.offsetWidth; style.height = node.data.offsetHeight; } catch (e) { //do alternate when error } style.cursor = 'pointer'; style.color = '#fff'; style.fontSize = '0.8em'; style.textAlign= 'center'; 
+1
source

You can use try ... catch:

 try{ allert('hello'); //Syntax error }catch(err){ console.log(err); } 
0
source

If you know that your code is likely to encounter an error (for some reason), you can catch and handle the errors with try / catch:

 try { // Code that is likely to error } catch(e) { // Handle the error here } 

You can either do nothing wrong or try to restore your application. In this case, you should probably try to find out why IE throws the error in the first place and sees if error suppression can be avoided.

Further reading:

0
source

Source: https://habr.com/ru/post/909089/


All Articles