Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE10 and jQuery: SCRIPT5009: "$" is undefined

I'm faced with this really annoying problem, it appears in IE10 like in IE9. Given this HTML:

<head>
    <title>Any Consult</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <!--[if lte IE 9]>
        <script src="scripts/IE9.js"></script>
    <![endif]-->
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script type="text/javascript" src="scripts/scripts.js"></script>
</head>

This (scripts.js) works fine in FF and Chrome, but IE10 throws the SCRIPT5009 error.

scripts.js is like (simple, but tested example):

$(document).ready(function() {
   alert('Hello');
});

IE10 does not load the jQuery-File and I tried nearly everything. I changed and reduced the filename, I spared the

<!--[if lte IE 9]>...

part, I tried

src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js"

but nothing happened. Because this is a new version of this question, I'd like to specify:

  1. how should I name the jQuery-File for IE(10)?
  2. where should I put the script tags in the HTML-Header?

Thanks a lot!

EDIT: Here the suggested HTML-version, which does not work, too:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
<script type="text/javascript" src="scripts/clocks.js"></script>
<!--[if lte IE 9]>
    <script src="scripts/IE9.js"></script>
<![endif]-->
<!--[if IE]><script type="text/javascript" src="scripts/excanvas.js"></script><![endif]-->

IE9.js is a browser polyfill file.

And here is my screenshot ("ist undefiniert" means "is undefined", "Die Webseite reagiert nicht" means "the page went down", "Debugger beenden" means "stop debugging", $('.aLang') is a class in my HTML.

Screenshot IE10 Bug Report

like image 201
BairDev Avatar asked Jun 02 '13 11:06

BairDev


2 Answers

I had this problem with IE and found that the jQuery javascript file was corrupt in the IE developer tool. This was caused in my case by HTTP GZIP compression being done by the server but IE wasn't decompressing the file. I guess that if you turn off static HTTP compression or exclude the application/x-javascript from whatever is doing the compression (Mine was done by FluorineFX for all files over 10Kb) it should work okay once you have cleared your browser cache to get rid of the compressed javascript file.

like image 167
Mike Kokitch Avatar answered Oct 17 '22 18:10

Mike Kokitch


Place the conditional script after the jQuery library:

<script type="text/javascript" src="scripts/jquery.js"></script>
<!--[if lte IE 9]>
<script src="scripts/IE9.js"></script>
<![endif]-->
like image 4
BenM Avatar answered Oct 17 '22 17:10

BenM