javascript iframe 监听自己被销毁
您可以在父窗口中监听iframe的unload事件,以便在iframe被销毁时触发相应的操作。
以下是示例代码:
var iframe = document.getElementById('my-iframe');
iframe.addEventListener('unload', function() {
// 在iframe被销毁时执行操作
});
请注意,如果iframe是跨域的,则无法访问其unload事件。此时,您可以使用postMessage来通知父窗口iframe已经被销毁。
原文地址: https://www.cveoy.top/t/topic/fsZJ 著作权归作者所有。请勿转载和采集!