问题现象:
我的页面中有4个iframe,开始我是将url直接放在每个iframe的src中,但这样会有一个问题,每次页面刷新后,那4个iframe加载出现异常,有时成功,有时失败(错误提示如下),要刷新好几次才能将所有iframe的内容显示出来
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
解决方案:
1、先将 iframe 的src 设置为空
2、然后通过调用 loadiframe() ,每次在一个iframe的 onload() 执行完后,再加载下一个iframe
<body onload="loadiframe()">
<div>
<div class="div-inline">
<iframe id="TopFrame" name="top111" scrolling="auto" frameborder="0" src=""
style="width:100%;height:100%;"></iframe>
</div>
<div class="div-inline">
<iframe id="TopFrame2" name="top1112" scrolling="auto" frameborder="0" src=""
style="width:100%;height:100%;"></iframe>
</div>
<div class="div-inline">
<iframe id="TopFrame3" name="top113" scrolling="auto" frameborder="0" src=""
style="width:100%;height:100%;"></iframe>
</div>
<div class="div-inline">
<iframe id="TopFrame4" name="top1114" scrolling="auto" frameborder="0" src=""
style="width:100%;height:100%;"></iframe>
</div>
</div>
<script>
function loadiframe() {
var iframe = document.getElementById("TopFrame");
iframe.src = "/KanbanItem1";
iframe.onload = function(){
iframe = document.getElementById("TopFrame2");
iframe.src = "/KanbanItem2";
iframe.onload = function(){
iframe = document.getElementById("TopFrame3");
iframe.src = "/KanbanItem3";
iframe.onload = function(){
iframe = document.getElementById("TopFrame4");
iframe.src = "/KanbanItem4";
};
};
};
}
</script>
</body>