Created
October 23, 2012 16:00
-
-
Save ilann/3939658 to your computer and use it in GitHub Desktop.
iframe memory leak demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script> | |
window.SAR = { | |
alive : true | |
}; | |
</script> | |
</head> | |
<body>iframe </body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<h2>Parent</h2> | |
<div> | |
<button id="btn_killer">kill iframe</button> | |
<button id="btn_test">test!</button> | |
</div> | |
<iframe id="iframe1" src="if.html" ></iframe> | |
<script> | |
var iframe = document.getElementById("iframe1"); | |
var parent_ref_keeper = "NOT SET YET!" ; | |
iframe.onload = function(){ | |
console.log ("iframe loaded"); | |
parent_ref_keeper = iframe.contentWindow.SAR; | |
console.log ("parent_ref_keeper set to = " , parent_ref_keeper); | |
}; | |
window.onload = function (){ | |
var btn_killer = document.getElementById("btn_killer").addEventListener("click" , function(){ | |
document.body.removeChild(iframe); | |
}); | |
var btn_test = document.getElementById("btn_test").addEventListener("click" , function(){ | |
console.log ("btn_test" , parent_ref_keeper); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment