Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internet Explorer 11 gives script error in PageRequestManager.js

I'm using ASP.NET 4.5 on the server and I have a .NET Windows application with a Web Browser control that navigates to the web page on the server.

If I run the Windows application on a system with Internet Explorer 11, I get a script error: "Object doesn't support property or method 'attachEvent'" when navigating to another page. The script file is ScriptResource.axd so it isn't any of my scripts.

I do know that Internet Explorer 11 doesn't support attachEvent anymore (replaced with attachEventListener?). That is however not of much help here, as the javascript is part of the framework, not in my code.

I found the javascript source for the framework here: http://ajaxcontroltoolkit.codeplex.com/SourceControl/latest#Client/MicrosoftAjax/Extensions/Sys/WebForms/PageRequestManager.js

// DevDiv Bugs 100201: IE does not set referrer header on redirect if you set window.location, inject anchor node instead
// dynamic anchor technique only works on IE
if (Sys.Browser.agent === Sys.Browser.InternetExplorer) {
    var anchor = document.createElement("a");
    anchor.style.display = 'none';
    // cancel bubble so body.onclick is not raised
     anchor.attachEvent("onclick", cancelBubble);
    // more code...
}

This is the Sys.Webforms.PageRequestManager module that is part of the core ASP.NET framework as far as I understand.

The line that performs attachEvent gives script error on Internet Explorer 11, but works great on older versions of Internet Explorer.

How to fix this problem? Are there any known workarounds? I couldn't fine any updates for this.

like image 648
tpe Avatar asked Nov 12 '13 14:11

tpe


People also ask

How do I enable JavaScript in IE 11?

Internet Explorer Click Tools > Internet Options. Click the Security tab > Custom Level. In the Scripting section, click Enable for Active Scripting. In the dialog box that displays, click Yes.

Why JavaScript is not working in Internet Explorer?

Internet Explorer When the "Internet Options" window opens, select the Security tab. On the "Security" tab, make sure the Internet zone is selected, and then click on the "Custom level..." button. In the Security Settings – Internet Zone dialog box, click Enable for Active Scripting in the Scripting section.

Does ie11 support JavaScript?

Internet Explorer 11 doesn't support JavaScript versions later than ES5. If you want to use the syntax and features of ECMAScript 2015 or later, or TypeScript, you have two options as described in this article. You can also combine these two techniques.


2 Answers

Try forcing the browser to render in IE 10 mode...

<meta http-equiv="X-UA-Compatible" content="IE=10" />
like image 139
bastos.sergio Avatar answered Oct 23 '22 23:10

bastos.sergio


I got that problem with jQuery 1.10 and it seems, that IE11 lacks the support of "attachEvent" which is used in jQuery and which seemed to be used by your framework as well. There is a Microsoft bugticket for that: Bugticket attachEvent IE11

I've found a solution in the related jQuery bugticket. Just insert the following code before your framework:

var isIE11 = !!(navigator.userAgent.match(/Trident/) && !navigator.userAgent.match(/MSIE/)); 
if (isIE11) {
    if (typeof window.attachEvent == "undefined" || !window.attachEvent) {
        window.attachEvent = window.addEventListener;
    }
} 

You first check if the browser is IE11 and then bind the attachEvent listener again so the error doesn't occur again.

like image 37
Sabrina Avatar answered Oct 23 '22 23:10

Sabrina