A script running inside an htmlFile ActiveX document can be made resident simply by storing a reference to the htmlFile object inside its own window. This creates a circular reference that prevents garbage collection, keeping the setInterval alive even after the main page navigates away.
<script language="JavaScript">
var axHtmlFile = new ActiveXObject("htmlFile");
var axWin = axHtmlFile.parentWindow;
// The key: a pointer to axHtmlFile stored inside its own window
axWin.selfReference = axHtmlFile;
axWin.setInterval('alert("Hello, World!")', 5000);
</script>
Works on both IE7 and IE8. Navigate away to any URL and the alert continues firing every five seconds. The selfReference property is what prevents the htmlFile object from being collected — without it, the interval stops as soon as the creating page unloads.
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