Suppose this is your iframe (ifr.htm)-
<html>
<head>
<script type="text/javascript">
function func() {
window.top.window.f = function() {
alert('iframe hack');
}
}
window.onload = function() {
alert('iframe loaded');
func();
};
</script>
</head>
<body>
this is the test iframe.
</body>
</html>
and this is your parent window-
<html>
<head>
<script type="text/javascript">
window.onload = function() {
i = document.getElementById('iframe'); //remove the iframe
i.parentNode.removeChild(i);
window.f(); //you can still call f() method
};
</script>
</head>
<body>
this is the parent window.
<iframe src="ifr.htm" id="iframe"></iframe>
</body>
</html>
This basically accesses the parent using top
and adds a function to it. So even when the iframe
is removed from the DOM, the function will still remain, as it was added to the parent.