Javascript that crashes IE

Recently I was helping my colleague to fix a strange bug in his Javascript. The bug behave like this:

  1. Open the web page in IE.
  2. After everything are loaded (HTML, images, scripts, …), click on address bar and press enter
  3. IE crashed 😦

When I try to identify the bug, I’ve created a simple page that can reproduce the bug.

crash.html

<div id="panel"></div>
<a href="#" onclick="loadScript(); return false;">Load script</a>

<script>
    var n = 0;
    var callback = function() {
        n++;
        var panel = document.getElementById("panel");
        panel.innerHTML = "loadScript called " + n + " times.";
        var node = document.getElementById("testid");
        node.parentNode.removeChild(node);
    }

    var loadScript = function() {
        var node = document.createElement("script");
        node.src="crash.js";
        node.id = "testid";

        document.getElementsByTagName("head")[0].appendChild(node);
    }

    window.onload = loadScript;
</script>

Continue reading

Advertisements