前提话:
搞性能的人都知道高性能网站建设指南的作者steve讲了很多怎么处理代码,使你的网站速度很快。也包括讲了Iframe 的blocking问题,今天在网上看了Aaron的关于讲Iframe的性能提出了新的思路。好的东东要分享,决定做个翻译(虽然英文很差但好东东就要说出来)。在性能方面的东东国内确实讲得很少。
Iframe setTimeout() does not work in IE9
Chad Barnsdale of Unfinishedman.com mentioned to me on May 25 that the Iframe setTimeout() technique does not work in IE9. And he was right. The file that gets loaded into the iframe simply does not load. Nothing happens. I will dive into this sometime soon. It's probably something small with the JavaScript code.
Chad Barnsdale of Unfinishedman.com mentioned to me on May 25 that the Iframe setTimeout() technique does not work in IE9. And he was right. The file that gets loaded into the iframe simply does not load. Nothing happens. I will dive into this sometime soon. It's probably something small with the JavaScript code.
在IE9中使用Iframe setTimeout()的方式不能工作。注释一下吧。在steve中讲了iFrame不阻塞时讲到可以使用Iframe setTimeout()可以解除阻塞,为了能了解setTimeout实现方式。我这里贴两段代码:
1.最为普通的iframe代码,blocking page
<iframe id=iframe1 src="iframe-empty.php?t=" width=95% height=150 border=2></iframe>
2.steve的setTimeout实现iframe代码
<iframe id=iframe1 src="" width=95% height=150 border=2></iframe>
<script type="text/javascript">
function setIframeSrc() {
iframe1 = document.getElementById('iframe1');
if ( iframe1 ) {
if ( -1 == navigator.userAgent.indexOf("MSIE") ) {
t_iframe = Number(new Date());
iframe1.src = "iframe-empty.php?t=";
}
else {
t_iframe = Number(new Date());
iframe1.location = "iframe-empty.php?t=";
}
}
else {
alert("ERROR: There was a race condition - the iframe doesn't exist.");
}
}
function setIframeSrc() {
iframe1 = document.getElementById('iframe1');
if ( iframe1 ) {
if ( -1 == navigator.userAgent.indexOf("MSIE") ) {
t_iframe = Number(new Date());
iframe1.src = "iframe-empty.php?t=";
}
else {
t_iframe = Number(new Date());
iframe1.location = "iframe-empty.php?t=";
}
}
else {
alert("ERROR: There was a race condition - the iframe doesn't exist.");
}
}
setTimeout(setIframeSrc, 5);
</script>
</script>
Demo: