0

I'm noticing a strange behaviour with IE10.

I have a javascript file with this content:

var x = 1;

//@deprecated, use static version
var y=function(interval){
    console.log(interval);
};

The file is encoded with UTF-8.

I have an html file with meta tag

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

If the previous file is included via <script> tag, it works.

If I instead download the file creating a script element via javascript and appending the script in the head:

var script = document.createElement('script'),
head = document.getElementsByTagName('head')[0];

script.type= 'application/javascript';
script.src = ''; // omissis

head.appendChild(script);

It works for IE11 but not for IE10: it is throwing error

(SCRIPT1004): expected ';'

The strange thing is: the line and column number of the error are pointing to the comma after the //@deprecated: but this should be a comment, it should not throw any error.

BTW: the javascript that creates the script tag and append it to the head is working for all javascript files and for all browser. It seems to be broken only if inside the file there is the //@deprecated comment.

Thank you, cheers

5
  • wild guess but try declaring the variables without comma and separate with a colon: var script = document.createElement('script'); var head = document.getElementsByTagName('head')[0];
    – mchl18
    Commented Nov 30, 2018 at 12:20
  • Hi mchl18, unfertunately that doesn't solve the problem. I also tried script.async = false; and script.charset = 'UTF-8'; but without luck. Commented Nov 30, 2018 at 13:05
  • Then I am clueless and sadly I also do not have a runnable IE to reproduce, good luck
    – mchl18
    Commented Nov 30, 2018 at 13:26
  • 1
    I try to make a test with IE 11 using IE 10 document mode. I try to follow the steps and create the file and try to run it. I find that it is working on my side without any error. Here is a testing result. i.postimg.cc/T34rwcdy/70.gif I suggest you to make a test with any other machine to check whether it can produce the same error or not. Commented Dec 3, 2018 at 6:12
  • Hi @Deepak-MSFT, I tried esactly your demo and: it worked! Now I'm gradually changing the working demo in my use case (that is broken) to see what is causing the problem. For example, in the working demo the files are not served through a server; so now I'm moving the files under tomcat to see if the problem is cause by Tomcat. I will update the post with the solution, if I will be able to find it. Thank you very much! Commented Dec 3, 2018 at 9:42

1 Answer 1

0

Ok, thanks to @Deepak-MSFT I found the error.

The error was caused by another script that was loaded before the execution of the snippet.

In this script, there was the code /@cc_on!@/ that activates the conditional compilation flag for IE(< 11) browser. Here is another stack overflow question related to this:

what does this comment /*@cc_on!@*/0 do inside an if statement in javascript?

If I comment out the line, the problem disappear.

Thanks to @Deepak-MSFT, because he tried to reproduce the problem by doing the steps indicated by me - this was my fault, because I descripted the minimal steps to reproduce the problem without actually doing a test by myself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.