IE9 throws exceptions when loading scripts in iframe. Why?

后端 未结 6 1334
失恋的感觉
失恋的感觉 2020-12-15 03:58

Precondition:

I have an aspx-page with iframe inside. This iframe points to the url handled by MVC on the same site (it\'s hybrid site, both standard ASP.NET and ASP

相关标签:
6条回答
  • 2020-12-15 04:23

    Try loading the javascript at the end after complete web page is loaded. I feel the script is executing even before the iframe is completely loaded.

    for some suggestion of scripting in IE9 view the given link below http://blogs.msdn.com/b/ie/archive/2010/06/25/enhanced-scripting-in-ie9-ecmascript-5-support-and-more.aspx

    0 讨论(0)
  • 2020-12-15 04:24

    Placing the following script block at the very top of the iFrame html <head> seems to resolve the issue in my case. Basically, it forces the iframe to reload, which as some have pointed out, solves the issue. It seems relatively safe, because, without things like 'Object' and 'Date', javascript is essentially useless.

    <script type="text/javascript">
        if(typeof(Object)==="undefined"){
            window.location.reload();
        }
    </script>
    
    0 讨论(0)
  • 2020-12-15 04:29
    function waitForjQuery(){
        if(typeof jQuery!='undefined'){
            //Do yor stuff!
        }
        else{
            setTimeout(function(){
                waitForjQuery();
            },500);
        }
    }
    waitForjQuery();
    
    0 讨论(0)
  • 2020-12-15 04:31

    I have encountered this same situation in the wild. Basic symptoms:

    • You load script code in an iframe
    • The script code runs early (from the head section or top of body)
    • IE complains about some missing native object

    I found that it can often be prevented by delaying the execution of the script code until onload or DOMContentLoaded... Not much help I know but this is one of the most difficult IE scripting bugs I have ever encountered. I upped the score of your question, hope it will be found by others as well and we can get a more detailed answer.

    Also see this question: Error in Internet Explorer 9 (not earlier versions or other browsers) when including jQuery in an iframe

    0 讨论(0)
  • 2020-12-15 04:35

    Further investigation revealed that the solution is to add the offending iframe to it's dom location BEFORE setting the 'src' attribute.

    Once the 'src' has been set, changing location of the iframe within the DOM stack forces IE9 to garbage collect it.

    Once 'src' has been set, iframe can be resized and changed via css positioning, but cannot change the relative location in the DOM stack.

    Often times, plugins like dialogs and lightboxes will stuff an iframe with src already set into the dom, then append / prepend or whatever, triggering the GC to take place.

    0 讨论(0)
  • 2020-12-15 04:47

    There is this msdn page about this bug (or feature).

    You get these kinds of errors when you move the iframe element around in DOM. In such cases, IE 9 garbage collects the iframe (causing your undefined bug) and reloads it at another position.

    In general, you should create the element, set its src attribute only once and then put it somewhere in the DOM tree once. It has nothing to do with the code which runs in the iframe itself.

    0 讨论(0)
提交回复
热议问题