删除iframe时如何触发onunload事件?
移除iframe时如何触发其卸载事件 使用下面的代码,当调用removeChild(iframe)时,不会触发onunload事件删除iframe时如何触发onunload事件?,iframe,triggers,removechild,onunload,Iframe,Triggers,Removechild,Onunload,移除iframe时如何触发其卸载事件 使用下面的代码,当调用removeChild(iframe)时,不会触发onunload事件 <!-- parent.html --> <html> <head> <title>remove iframe</title> <script type="text/javascript"> window.onload = function() {
<!-- parent.html -->
<html>
<head>
<title>remove iframe</title>
<script type="text/javascript">
window.onload = function() {
var button = document.getElementsByTagName("BUTTON")[0];
button.onclick = function() {
document.body.removeChild(document.getElementsByTagName("IFRAME")[0]);
};
};
</script>
</head>
<body>
<iframe src="./son.html" />
<button>Remove iframe</botton>
</body>
</html>
<!-- son.html -->
<html>
<head>
<title>son html</title>
<script type="text/javascript">
window.onload = function() { alert("hello"); };
window.onunload = function() { alert("world!"); };
</script>
</head>
<body style="background-color:#aaccee;">
</body>
</html>
移除iframe
window.onload=函数(){
var button=document.getElementsByTagName(“按钮”)[0];
button.onclick=函数(){
document.body.removeChild(document.getElementsByTagName(“IFRAME”)[0]);
};
};
移除iframe
子html
window.onload=function(){alert(“hello”);};
window.onunload=function(){alert(“world!”);};
如何触发它?在删除帧之前,您可以将iframe元素的src属性设置为“about:blank”,检查这是否使iframe触发onnload事件 例如:
它在firefox中工作得很好,但在Chrome中却不行。有什么想法吗?
var iframe = document.getElementsByTagName("IFRAME")[0];
iframe.src = "about:blank";
document.body.removeChild(iframe);