JQuery 2.1.1 in IE9 receives the error: 0x800a01b6 - Microsoft JScript runtime error: the object does not support the property or method 'addEventListener'

Using Visual Studio 2013, I ported the Asp.Net Webforms / MVC 3 hybrid web application to Asp.Net Webforms / MVC 5.1. As part of the migration, I upgraded Jquery from 1.9.1 to 2.1.1 using the NuGet package manager.

When I run the application in the Visual Studio 2013 debugger in Chrome, I have no problem.

When I run the application in the Visual Studio 2013 debugger in IE 9 (compatible mode is not enabled), the main page with these two tags script loads first:

<script src="/Scripts/jquery-2.1.1.js" type="text/javascript"></script> <script src="/Scripts/jquery-ui-1.10.4.js" type="text/javascript"></script> 

The error of this Javascript error is:

 Unhandled exception at line 3425, column 4 in http://localhost:25378/Scripts/jquery-2.1.1.js 0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'addEventListener' 

I understand that jQuery 2 does not work with IE 8 and below, but I can not find any documentation that notes any problems with IE 9.

Error in line 3425 jquery-2.1.1.js inside jQuery.ready.promise function:

 document.addEventListener( "DOMContentLoaded", completed, false ); 

Oddly enough, when I stop at the error, view the document object in the debugger and expand the "Methods" node, I see the "addEventListener" method. It looks like jQuery is not allowed to see this method.

I would love to move on to jQuery 2, and from everything I read, jQuery 2 should work with IE9. Any tips to fix this problem?

+7
javascript jquery
source share
4 answers

Thanks to αΎ αΏ—α΅² ᄐ ᢌ and QBM5 for your comments, the answer in this case was to delete

 <meta http-equiv="X-UA-Compatible" content="IE=8"> 

from the header of the main page, since it puts the browser into compatibility mode with IE 8, and IE 8 is not compatible with JQuery 2.

+9
source share

I was getting the same error with the new web app in VS2013 Ultimate. It turns out that IE11 works in compatibility mode - disabling this feature got rid of the error

+8
source share

I got a similar exception when using jQuery in IE8. and found a solution

 <head id="Head1" runat="server"> <!--[if lt IE 9]> <script src="/js/trirand/jquery-1.11.1.min.js" type="text/javascript"></script> <![endif]--> <!--[if gt IE 8]> <script src="/js/trirand/jquery-2.1.1.min.js" type="text/javascript"></script> <![endif]--> </head> 

You can change the version if necessary.

From code: IE8 and lower versions support jQuery1X versions

Jquery2x versions work in IE9 and later.

Good luck.

+1
source share

You can add the code below to your web configuration file to set document mode:

 <system.webServer> <httpProtocol> <customHeaders> <add name="X-UA-Compatible" value="IE=EmulateIE9" /> </customHeaders> </httpProtocol> </system.webServer> 
+1
source share

All Articles