IE8 throws JavaScript syntax error - outside of script

I got a strange problem when IE8 reports a JavaScript error outside the script tag (or as it claims), and breaking all further JS on the page. Here is the violation code:

<script type="text/javascript">//<![CDATA[ function emailReport() { var params = window.location.search; var url = "scripts/someScript.php" + params; ajaxwl(url, false, null, function() { alert("Report successfully sent."); }); } //]]></script> <h2>Analyst Report</h2> 

ajaxwl () is just a wrapper over jQuery.ajax () and is used in hundreds of places around the site without any problems.

IE claims that the syntax error (it does not specify which type) has a 23 line character with a </script> . This is especially strange since this line has only 15 characters. However, if I check the intended location in the IE8 developer tools, it actually puts the error in the middle of the <h2> on the next line.

Here is the official IE error message:

 User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; InfoPath.1; MS-RTC LM 8) Timestamp: Tue, 12 Jun 2012 21:19:38 UTC Message: Syntax error Line: 175 Char: 23 Code: 0 

Given that IE is not telling me the actual error message, I have not yet been able to find anything about this on the Internet. JSLint provides nothing useful, and it works flawlessly in Chrome and FF. Am I missing something?


EDIT: My hunch is that even though IE reported an error in the code snippet above, it actually dies somewhere else. This is like consensus. I think I’ll look at the page and see if I’m lucky and find an error.

+4
source share
2 answers

IE is known for not specifying the file in which the error occurred, or not specifying it correctly. Try running it in the IE debugger and see if there is an error in line 175 of another file.

EDIT The debugger does not work, so you have to do it in a complicated way: save the page to your disk; merge all Javascript files into one large file; include this file from a blank page. Now the line number will be different but accurate in the only JS file you have.

My prediction: terminal comma. The following line of code is legal in Javascript, but not in IE "JScript".

  var x = [ 0, ]; 

"Steve Jobs is dead, and Bill Gates is alive because God is not. But after 100 years, Jobs will remember with Edison and Eli Whitney, while Gates will be forgotten because there is justice."

+3
source

I just ran a window with IE 8.0.7601 and did not find any syntax problems with this code.

 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>I AM YOUR DOCUMENT TITLE REPLACE ME</title> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> </head> <body> <div> <script type="text/javascript">//<![CDATA[ function emailReport() { var params = window.location.search; var url = "scripts/someScript.php" + params; ajaxwl(url, false, null, function() { alert("Report successfully sent."); }); } //]]></script> <h2>Analyst Report</h2> </div> </body> </html> 
+2
source

All Articles