Error in Internet Explorer 9 (not earlier versions or other browsers) when including jQuery in an iframe

我们两清 提交于 2019-12-30 08:09:10

问题


Basically I have a page that launched a fancybox iframe. In that iframe I also include jQuery. But when I testing it in Internet Explorer 9 it gives me the error

Line: 68\n Error: 'Object' is undefined`

This error is in file jquery-1.4.1.js and the line in question is the second line of this:

// Save a reference to some core methods
toString = Object.prototype.toString,
hasOwnProperty = Object.prototype.hasOwnProperty,
push = Array.prototype.push,
slice = Array.prototype.slice,
indexOf = Array.prototype.indexOf;

which is the last lines of the var jQuery = function( selector, context ) {.

No problem if I'm in compatibility view, no problem in any other browsers, just Internet Explorer 9 in Internet Explorer 9 mode and Internet Explorer 9 standards. If I ignore the error I see no problems using any version of jQuery.

What's up, and what I can do to fix?


回答1:


The problem was fixed when I removed the SRC attribute from the iframe and I added onOpen event to jQuery's dialog:

open: function()
  {
    document.getElementById("mainFrame").src = "/login.aspx";
  }



回答2:


I had the EXACT same issue, but the cause of mine was different. I figured I'd share here in case others were in the same boat as me - especially given that it took me about 4 hours to track down...

Our main page had an iframe which ended up having its src attribute changed twice in a very short amount of time (we were actually loading the same src twice by accident - once directly in the HTML and then again on page load via JavaScript). I'm not sure why Internet Explorer 9 chokes, but I'm guessing that the frame was partially through initializing its scripts when the src was set again, putting the JavaScript engine into an unhappy state. Either way I'm glad I found it, since we shouldn't have been loading the frame twice!

However, the real reason why Internet Explorer 9 died so bad is a mystery.




回答3:


This is a related issue: IE9 throws exceptions when loading scripts in iframe. Why?

There seems to be some real issue in Internet Explorer with native global objects such as 'Function' and 'Object' being undefined in some circumstances when scripts are loaded early (in the head section) of an iframe...

I placed a bounty on that other question to get some more attention to it.

From experience I know this issue also exists in IE8, but it was more rare there it seems. Looks like in IE9 it has gotten worse...




回答4:


D'oh, thought I had the latest fancy box. Turns out I had 1.3.1, 1.3.4 fixes this issue.

UPD(sompylasar): In fact, that was fixed in 1.3.2 (see the changelog). I've compared the source code of 1.3.2 with 1.3.1 and found the following difference which solves the issue:

content.find('iframe').attr('src', isIE6 && /^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank');

where isIE6 evaluates to:

isIE6 = $.browser.msie && $.browser.version < 7 && !window.XMLHttpRequest,

This snippet should be executed before removing the iframe from the DOM.



来源:https://stackoverflow.com/questions/6528946/error-in-internet-explorer-9-not-earlier-versions-or-other-browsers-when-incl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!