等待弹出窗口完成加载执行javascript
我有一个弹出窗口,其中显示了多个图像,图像的数量可以根据用户所做的改变。这些图像每次加载大约需要1.5秒,但这可能会根据机器速度而变化 我需要一种方法来等待弹出完成加载所有的图像,然后执行一个脚本,什么是最好的方式做到这一点 编辑:等待弹出窗口完成加载执行javascript,javascript,Javascript,我有一个弹出窗口,其中显示了多个图像,图像的数量可以根据用户所做的改变。这些图像每次加载大约需要1.5秒,但这可能会根据机器速度而变化 我需要一种方法来等待弹出完成加载所有的图像,然后执行一个脚本,什么是最好的方式做到这一点 编辑: popup.document.body.setAttribute("onload","alert('hello');"); //Wait for the popup to finish loading popup.onload = function() {
popup.document.body.setAttribute("onload","alert('hello');");
//Wait for the popup to finish loading
popup.onload = function() {
popup.alert("loaded");
};
以上这些都不起作用
编辑2
多亏了迪奥德乌斯,现在可以工作了。代码如下:
popup.document.write(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'+
'<html><head>'+
'<script type="text/javascript">'+
'var i = '+doc('print_container2').getElementsByTagName('img').length+'; var c = 0;'+
'function count_loaded() {'+
'if (c == i) {'+
'document.getElementById("print_container").style.display = "block";document.getElementById("loading").style.display = "none";'+
'focus();print();close();'+
'}'+
'}'+
'</script>'+
' <link rel="stylesheet" href="css/css.css">'+
'</head><body><h1 id="loading">Loading... please wait...</h1>'+
'</body></html>'
);
popup.document.write(
''+
''+
''+
“var i=”+doc('print_container2')。getElementsByTagName('img')。长度+”;var c=0;'+
'函数计数\u已加载(){'+
'如果(c==i){'+
'document.getElementById(“打印容器”).style.display=“块”document.getElementById(“加载”).style.display=“无”;'+
'焦点();打印();关闭();'+
'}'+
'}'+
''+
' '+
“正在加载…请稍候…”+
''
);
以下是图片:
$hires .= "<img onLoad=\"c++;count_loaded();\" id=\"L".$key."_".$key2."_".$i."\" data-quantity=\"".$value2['quantity']."\" onclick=\"disable_print(this,'print_container')\" src=\"".$_SESSION['ROOT_DIR']."php/generateimage.php?imgname=".$_SESSION['ROOT_PATH']."data/images/".$value2['location']."&restraint=".$restraint."\" class=\"\" />";
$hires.=”;
请参阅onLoad事件 如果我没有弄错的话,
window.onload
事件只有在加载所有图像后才会触发我正在尝试,但似乎没有任何效果,请参阅更新的帖子正文。onload
与window.onload
不同。只有后者在加载所有内容后触发,可能是使用jQuery@Diodeus的重复项,我不使用它。