function pos(obj) {
var curleft = 0;
var curtop = 0;
if (obj.offsetParent) {
do {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
}
obj = null;
return {left:curleft, top:curtop};
}
function loadPage(url) {
var y = document.getElementById('container');
var x = document.getElementById('applicationFrame');
var p = pos(y);
if (x.src) {
var tmp = y.cloneNode(false);
var tmpIF = x.cloneNode(false);
tmpIF.src = url;
tmp.appendChild(tmpIF);
tmp.style.position = 'absolute';
tmp.style.visibility = 'hidden';
tmp.style["z-index"] = 20;
tmp.style.top = p.top;
tmp.style.left = p.left;
y.id = "delete";
x.id = "deleteApplicationFrame";
document.getElementsByTagName("body")[0].appendChild(tmp);
tmpIF = null; tmp = null;
}
setTimeout("document.getElementById('applicationFrame').style.visibility = 'visible'; var i = document.getElementById('deleteApplicationFrame'); i = i.contentDocument || i.contentWindow.document; i.documentElement.parentNode.removeChild(i.documentElement); i=null; i=document.getElementById('delete'); i.parentNode.removeChild(i); i=null;", 500);
y = null; x = null; p = null;
}
<div id="container">
<iframe id="applicationFrame" application="yes" trusted="yes" frameborder="0" src="main.php"/>
</div>
在不了解整个应用程序的情况下,很难判断可能发生了什么。特别是IE6是一个内存泄漏的b..ch。
一些阅读链接
Understanding and Solving Internet Explorer Leak Patterns
Fixing Leaks
Memory Leakage in Internet Explorer - revisited
src
W3CHTMLDOM规范中没有真正指定不同的值,或者是(链接任何人?)?
我建议你设定一个初始值
src="main.php"
值,而不是使用
loadPage('main.php');
并为iframe设置一个名称。
理想情况下,您的菜单项是
<a>
然后您可以使用
<a href="notmain.php" target="nameOfYourIFrame">FooBar</a>
而不是基于javascript的解决方案