Javascript 或 Jquery:将 html 写入 iframe 不会触发 $(document).ready 在 IE 中
Javascript or Jquery: Write html to iframe not fire $(document).ready in IE
这是我的情况。
主页:
<script type="text/javascript">
function load_frm()
{
if($.browser.msie == true) {
var frame = document.getElementById('frm');
frame.contentWindow.document.write(patch_html);
}
else {
$("#frm").attr('src', "data:text/html;charset=utf-8," + escape(patch_html));
}
}
</script>
<html>
<body>
<input type="button" onclick="load_frm()">
<iframe id="frm"></iframe>
</body>
</html>
patch_html 包含 $(document).ready 需要在 iframe 完全加载后触发 更改 iframe 中的一些元素样式.
jquery 包含在 patch_html 的 header 中。
此代码在 firefox 中运行良好,但在 IE 中运行不正常。
我不得不使用 write(对于 IE)和 attr('src', "data:text/html...") 的原因是 html 没有 脚本改变一些元素样式,它只在某些特定条件下注入
我尝试了 iframe 的 onLoad,但它不起作用。它在资源完全加载之前触发。
我创立了答案:
javascript-how-to-load-dynamic-contents-html-string-json-to-iframe
我认为问题是
iframedoc.open();
iframedoc.writeln(patch_html);
iframedoc.close();
文档需要open/close大概。
可能使用:-
$('iframe#frm').load(function() {/*do something here*/});
Here is the post which will help you.
我找到了答案:javascript-how-to-load-dynamic-contents-html-string-json-to-iframe
我认为问题是
iframedoc.open();
iframedoc.writeln(patch_html);
iframedoc.close();
该文件可能需要open/close。
这是我的情况。
主页:
<script type="text/javascript">
function load_frm()
{
if($.browser.msie == true) {
var frame = document.getElementById('frm');
frame.contentWindow.document.write(patch_html);
}
else {
$("#frm").attr('src', "data:text/html;charset=utf-8," + escape(patch_html));
}
}
</script>
<html>
<body>
<input type="button" onclick="load_frm()">
<iframe id="frm"></iframe>
</body>
</html>
patch_html 包含 $(document).ready 需要在 iframe 完全加载后触发 更改 iframe 中的一些元素样式.
jquery 包含在 patch_html 的 header 中。 此代码在 firefox 中运行良好,但在 IE 中运行不正常。
我不得不使用 write(对于 IE)和 attr('src', "data:text/html...") 的原因是 html 没有 脚本改变一些元素样式,它只在某些特定条件下注入
我尝试了 iframe 的 onLoad,但它不起作用。它在资源完全加载之前触发。
我创立了答案: javascript-how-to-load-dynamic-contents-html-string-json-to-iframe
我认为问题是
iframedoc.open();
iframedoc.writeln(patch_html);
iframedoc.close();
文档需要open/close大概。
可能使用:-
$('iframe#frm').load(function() {/*do something here*/});
Here is the post which will help you.
我找到了答案:javascript-how-to-load-dynamic-contents-html-string-json-to-iframe
我认为问题是
iframedoc.open();
iframedoc.writeln(patch_html);
iframedoc.close();