JQuery security error in Opera and Internet Explor

2020-04-10 03:10发布

问题:

I am developing an app for social network which works in IFrame. The app works just fine in Google Chrome and Microsoft Firefox browsers, but in Opera 12.15 JQuery library v1.10.1 fails to load with security error Unhandled error: Security error: attempted to read protected variable on line 1513.

The screenshot is here:

It looks like the same bug exists in Internet Explorer 10.

How to deal with it?

UPDATE:

I have made dirty hack by commenting the lines 1513-1517 in the code of jquery:

   // Support: IE>8
   // If iframe document is assigned to "document" variable and if iframe has been reloaded,
   // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936
  /*if ( parent && parent.frameElement ) {
        parent.attachEvent( "onbeforeunload", function() {
            setDocument();
        });
    }*/

The functionality of my app seems to work now, maybe it is necessary to create issue in JQuery repo...

回答1:

Bug report was created - http://bugs.jquery.com/ticket/13980. Bug is now fixed.



回答2:

Add this before you include JQuery:

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

Hope it helps, It worked for me.