Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';t在IE9中更改iframes onload侦听器_Javascript_Jquery_Html_Iframe_Onload - Fatal编程技术网

Javascript Can';t在IE9中更改iframes onload侦听器

Javascript Can';t在IE9中更改iframes onload侦听器,javascript,jquery,html,iframe,onload,Javascript,Jquery,Html,Iframe,Onload,我在一个外部javascript文件中有以下代码 jQuery(function ($) { //////////////////////UPCOMING EVENTS JSON SERVER START/////////////////////////// var eventList = $("#eventList"); //cache the element $.getJSON("/JsonControl/Events.json", function (jsonO

我在一个外部javascript文件中有以下代码

jQuery(function ($) {

    //////////////////////UPCOMING EVENTS JSON SERVER START///////////////////////////

    var eventList = $("#eventList"); //cache the element
    $.getJSON("/JsonControl/Events.json", function (jsonObj) {
        val = "";
        for (var i = 0; i < jsonObj.events.length; ++i) {
            val += "<p>" + jsonObj.events[i].dateMonth + "/" + jsonObj.events[i].dateNumber +
                "/" + jsonObj.events[i].dateYear + " - <span id='EL" + i + "' class='link' " + 
                "onclick=plotEvent(" + i +")>" + jsonObj.events[i].title + "</span></p>";
        }
        eventList.html(val);
    });

    //////////////////////UPCOMING EVENTS JSON SERVER END/////////////////////////////

});

function plotEvent(index)
{
    $.ajax({
        url: "/JsonControl/Events.json",
        dataType: 'json',
        async: false,
        success: function (jsonObj) 
        {
            var eventBox = window.frameElement;
            alert("This alert fires in all browsers, including IE9")
            eventBox.onload = function () 
            {
                alert("This alert doesn't fire in IE9.")
                window.frameElement.onload = null; // unset it so it only fires once
                eventBox = eventBox.contentDocument || eventBox.contentWindow.document;
                eventBox.getElementById("title").innerHTML = (jsonObj.events[index].title);
                eventBox.getElementById("content").innerHTML = (jsonObj.events[index].explanation);
                eventBox.getElementById("dateHolder").innerHTML = (jsonObj.events[index].dateMonth + "-" + jsonObj.events[index].dateNumber + "-" + jsonObj.events[index].dateYear);
            };
            eventBox.src="/Event htms/Event.htm";
        }
    });
}

有没有解决这个问题的方法,或者这就是为什么iFrame没有被更多地使用(也就是说,IE不完全支持它们)?

试试
eventBox.contentWindow.onload
或者
$(eventBox.load)(function)
谢谢你的尝试,但这两种解决方案都不起作用,另外,我在另一个从主页执行的外部javascript文件中使用了非常类似的代码,它可以很好地更改iframes onload事件。它的工作原理是:var eventBox=document.getElementById(“eventBox”);eventBox.onload=function(){//code here}再试一次:我一直在使用iframe,而且只在IE9中使用。这是我最常用的代码(希望有帮助):var context=$(“#iframe”);context.one('load',function(){alert('loaded');});我会试一试,这样如果它起作用,我可以接受你的答案,但是,可能需要一段时间才能恢复到昨天的状态(我今天早上放弃了,并将其转换为服务器端处理,尽管我不希望在这个页面上这样做)。我会让你知道的!我刚刚尝试了你的最终解决方案,但是,唉,没有用。我确信您的代码很好,但是我有很多带有多个document.ready、jQuery(function($){})和html onload事件的外部脚本,所以可能有冲突。哦,好吧,我想这只是C#如何比JavaScript更强大的另一个例子(我承认这不是一个公平的比较,但我也不认为这是苹果对桔子的比较)。我会处理这个服务器端,让C来做。反正速度更快。非常感谢你的帮助,如果我浪费了你的时间。
eventBox.onload = function () 
        {
            alert("This alert doesn't fire in IE9.")
            window.frameElement.onload = null; // unset it so it only fires once
            eventBox = eventBox.contentDocument || eventBox.contentWindow.document;
            eventBox.getElementById("title").innerHTML = (jsonObj.events[index].title);
            eventBox.getElementById("content").innerHTML = (jsonObj.events[index].explanation);
            eventBox.getElementById("dateHolder").innerHTML = (jsonObj.events[index].dateMonth + "-" + jsonObj.events[index].dateNumber + "-" + jsonObj.events[index].dateYear);
        };