用 document.readyState == "complete" 判断页面是否加载完成。
document.onreadystatechange = function(){
if(document.readyState=="complete")
{
alert('加载完毕');
}
}
if(document.readyState=="complete")
{
alert('加载完毕');
}
}
var leftDocument=window.parent.frames("leftFrame").document; if(leftDocument.readyState == 'loaded' || leftDocument.readyState == 'complete') { leftDocument.getElementById("notes").style.display = 'block'; leftDocument.getElementById("others").style.display = 'none'; }
<script language="javascript"> if (document.readyState=="complete") { AdjustImageSize(); } else { document.onreadystatechange = function() { if (document.readyState == "complete") { AdjustImageSize(); } } } function AdjustImageSize() { var imageWidth = document.all["SendPic"].width; var imageHeight = document.all["SendPic"].height; if (imageWidth == 0 && imageHeight == 0) { document.write ("图片下载失败,请刷新!"); return; } if (imageWidth > 160 || imageHeight > 160) { if (imageWidth > imageHeight) { k = 160 / imageWidth; imageHeight = imageHeight * k; imageWidth = 160; } else { k = 160 / imageHeight; imageWidth = imageWidth * k; imageHeight = 160; } document.all["ImgResized"].value = "1"; } document.all["SendPic"].width = imageWidth; document.all["SendPic"].height = imageHeight; document.all["ImgWidth"].value = imageWidth; document.all["ImgHeight"].value = imageHeight; } </script>