一个子页面是一个iframe,在子页面里添加了unload事件后,在关闭这个子页面时unload事件
没有触发。IE各种版本都不能触发,chrome,firefox都可以触发;该如何解决?
//子页面的window
window.onunload = function(){};
//父页面的iframe
iframe.onunload = function(){};
//在IE下都无效。
js
var iframe = document.getElementById("iframe"); iframe. onload = iframe. onreadystatechange = function() { if (!iframe.readyState || iframe.readyState == "complete") { alert("Local iframe is now loaded."); } } iframe.src = "http://JSLite.io";
你试一试 onbeforeunload
onunload
unload是自己封装的事件?
下面这样关闭你试一试能不能触发呢?
html
<iframe id="www" src="http://JSLite.io"></iframe>
js
var el = document.getElementById("www"); if (el) { el.contentWindow.document.write(''); el.contentWindow.document.clear(); var p = el.parentNode; p.removeChild(el); } window.close();