-1

I have a conditional when I execute this On IE v11 event the first block is true is not execute because I have error on my second one, My question is how I can void this behavior I Mean in this case I want to show the alert and don't execute nothing more if I am IE v11.

if (window.navigator.userAgent.indexOf('Trident/') > 0) {
        alert('this browser is not supported');
         return
    } else {
        var se = `some here`; // <- this is not supported on EI v11
        console.log('here',se);
}
  • 1
    Don't use literal strings if the browser won't support it. ` <- this character – John Jul 26 '19 at 17:14
  • Yes but I need use it, I want to prevent this is I am on IE – Alfredo Izquierdo Jul 26 '19 at 17:17
  • Possible duplicate of [JavaScript backtick multiline string not working in Internet Explorer](https://stackoverflow.com/questions/42493557/javascript-backtick-multiline-string-not-working-in-internet-explorer) and [Template literals not working in IE11](https://stackoverflow.com/questions/40871705) – adiga Jul 26 '19 at 17:19
  • 1
    I don't think you can opt-out from code when the code itself is not syntactically valid for the JavaScript engine. You'll possibly need to move code to an external file and skip the file entirely or use a transpiler as adiga suggests. – Álvaro González Jul 26 '19 at 17:23

1 Answers1

0

Well, its a dirty solution and I highly do not recommend to use it. But you can use eval like that:

if (window.navigator.userAgent.indexOf('Trident/') > 0) {
  alert('this browser is not supported');
  return;
} else {
  eval('var se = `some here`'); // <- this is not supported on EI v11
  console.log('here',se);
}