0

I have code that use ES6 and jQuery Terminal and I want to show error if syntax error happen (in Terminal) which is probably because browser don't support ES6.

I have code like this:

window.onerror = function(message) {
   message += '. Your browser may not support ES6.';
   var term = $('body');
   var args = [].slice.call(arguments);
   if (term.hasClass('terminal')) {
       $.terminal.active().error(message);
   } else {
       $('body').terminal(function() {
           this.error('You need to use modern browser');
       }, {greetings:greetings}).error(message);
   }
};

I made syntax error in code I've put <> that simulat syntax error that would happen in IE for var {foo} = bar. But the terminal don't show up and there was no error on screen.

1 Answer 1

1

The problem was that onerror handler was in the same script as the code that was triggering syntax error, so the execution was aborted and onerror was not executed.

Solution was to put onerror handler in separated <script> tag before my code, like this:

  <script>
   var greetings = 'greeting';
   window.onerror = function(message) {
       message += '. Your browser may not support ES6.';
       var term = $('body');
       // only ES5
       var args = [].slice.call(arguments);
       if (term.hasClass('terminal')) {
           $.terminal.active().error(message);
       } else {
           $('body').terminal(function() {
               this.error('You need to use modern browser');
           }, {greetings:greetings}).error(message);
       }
   };
  </script>
  <script src="es6-library.js"></script>
  <script>
  /* my ES6 code */
  </script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.