7

Using Visual Studio 2013, I migrated a hybrid Asp.Net Webforms/MVC 3 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 (compatibilty mode is not on) a master page with these two script tags 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>

It fails with this Javascript error:

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 realize that Jquery 2 does not work with IE 8 and below, but I cannot find any documentation noting any issues with IE 9.

The error occurs on line 3425 of jquery-2.1.1.js inside the jQuery.ready.promise function:

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

Strangely, when I stop at the error, examine the document object in the debugger and expand the "Methods" node I can see the "addEventListener" method. It is as if Jquery does not have rights to see the method.

I'd very much like to move up to Jquery 2, and from everything I've read Jquery 2 should work with IE9. Any advice on fixing this issue?

Tom Regan
  • 3,580
  • 4
  • 42
  • 71
  • jQuery 2.1's API is identical to jQuery 1.11; the only advantage is the file size. Try switching to 1.11.1 – Blazemonger Jul 02 '14 at 14:28
  • I realize that. I want to switch to Jquery 2 exactly because of the smaller file size. I'm wondering why it fails in IE9 for me. According to everything I've read it should work with IE9. – Tom Regan Jul 02 '14 at 14:34
  • do you have a doctype defined? have you tried html5 ` `? – wirey00 Jul 02 '14 at 14:41
  • Yes I do have at the top of the page. – Tom Regan Jul 02 '14 at 14:47
  • 2
    try adding `` right after the opening head tag – wirey00 Jul 02 '14 at 14:58
  • 1
    Check your compatibility mode, if you are running the browser in compatibility mode it is basically the same thing as running an older version of IE, so the new jquery will not work, the suggestion above will force IE to NOT use compatibility mode. – QBM5 Jul 02 '14 at 15:10
  • Thank you both for pointing me to the solution. Found this little bugger in the daisy-chain of master pages: , which of course put the browser into compatibility mode. – Tom Regan Jul 02 '14 at 19:19

4 Answers4

9

Thank you ᾠῗᵲᄐᶌ and QBM5 for your comments, the answer in this case was to remove

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

from the master page header, because it put the browser into IE 8 compatibility mode, and IE 8 is not compatible with JQuery 2.

Tom Regan
  • 3,580
  • 4
  • 42
  • 71
8

I was getting the same error with a brand new web app in VS2013 Ultimate. Turns out IE11 was running in compatibility mode - turning that off got rid of the error

PTansey
  • 567
  • 4
  • 12
1

I was getting similar exception while using JQuery in IE8. and found 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 version if need.

From the code: IE8 and lesser versions support jQuery1X versions

Jquery2x versions are working in IE9 and higher versions.

Good luck

Muru Bakthavachalam
  • 1,340
  • 12
  • 8
1

You can add below code in your web config file for setting document mode:

<system.webServer>
  <httpProtocol>
    <customHeaders>
     <add name="X-UA-Compatible" value="IE=EmulateIE9" />
    </customHeaders>
 </httpProtocol>
</system.webServer>
Sheridan
  • 68,826
  • 24
  • 143
  • 183
anshul
  • 25
  • 1
  • 9