[英]document.frame is not working in ie11
在沒有兼容模式的IE 11中執行時,出現了未定義的對象錯誤。 它可以在11兼容模式下正常工作。
樣例代碼:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script>
function test() {
var parent = document.getElementById("tabPaneMain");
var doc = document;
var html = '<div class="tab-page" id="tabCust" style="width: 100%; height: 95%">'
+ '<h2 class="tab">Customer</h2>'
+ '<table cellpadding=2 cellspacing=0 width="100%" height="100%">'
+ '<tr><td valign=top id=iframeparent_tabCust>'
+ '<iframe name="iframe_tabCust" id="iframe_tabCust" src="overview.html" style="width=100%; height: 100%;" scrolling="no" frameborder=0></iframe>'
+ '</td></tr></table></div>';
var node = doc.createElement("DIV");
node.innerHTML = html;
parent.appendChild(node);
var test = node.document.frames["iframe_tabCust"];// undefined error: when execute in ie 11 without compatibile mode
}
</script>
</head>
<body>
<div class="tab-pane" id="tabPaneMain" style="left: 10px; height: 100%" />
<button id="btn" type="button" onclick="test();">
click
</button>
</body>
</html>
提前致謝
您的node
變量是一個div
元素。 最后我檢查了一個div沒有document
屬性。 所以node.document
將是未定義的,因此node.document.frames
將是一個錯誤。
window.frames
是獲取框架列表的標准位置。
由於框架上有唯一的ID,因此獲取框架的最簡單且“支持跨瀏覽器”的方式可能是:
document.getElementById("iframe_tabCust")
那么節點應該沒有文檔,所以應該
window.frames["iframe_tabCust"]
或只是按id引用
document.getElementById("iframe_tabCust")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.