带有 src 的 iframe onload 在 IE11 中不起作用

iframe onload with src not working in IE11

我有一个 JavaScript 程序可以获取 txt 文件的最后修改日期。该代码在 Firefox 中运行良好,但由于某种原因,它在 IE11 中没有任何作用。下面列出了我的代码。

JavaScript代码:

function getLastMod(){
    var myFrm = document.getElementById('myIframe');
    var lastMod = new Date(myFrm.contentWindow.document.lastModified);
    var getSpan = document.getElementById('LastModified');
    getSpan.innerHTML += "<font color=red> (File Last Updated: " + lastMod.toLocaleString() + ")</font>";
}

HTML代码:

<span id="LastModified"></span>
<iframe id="myIframe" onload="getLastMod()" src="date.txt" style="display:none;"></iframe>

我尝试在标签中定义事件时遇到了类似的问题。我从 javascript.

中分配事件得到了更好的结果
<script type="text/javascript">
    document.getElementById('myIframe').onload = function() {
        getLastMod();
    }
</script>