views:

93

answers:

2

Hi,

I've tried the following HTML code on several different Windows 7 computers with Internet Explorer 8, and everywhere this crashes Internet Explorer. I have not been able to reproduce this with IE7, or on Windows XP with IE8.

<!doctype html>

<head>
<title>Crashes IE8 on Win7</title>
<style>
article { display: block; }
</style>
<script>
document.createElement('article');
document.createElement('nav');

function initialize() {
    var map = new google.maps.Map(document.getElementById("map_canvas"), {});
}

function loadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?sensor=false&amp;callback=initialize";
    document.body.appendChild(script);
}

window.onload = loadScript;
</script>
</head>
<body>

<nav><ul><li>
    <div id="map_canvas"></div>
    <article>
</li></ul></nav>

</body>

The only real bug in the page, is the missing </article> tag. The rest is all required to make IE crash. I'm sure I could have narrowed it down further by disassembling the Google Maps API, but that went a bit too far for me.

Can anybody else reproduce this, or is their some weird configuration that only applies to all the machines I have tested this on?

EDIT: To be more clear, I am not looking for a fix to my code. (The fix would be: add missing </article> tag.) I am looking if this crashes IE8 on Win7 other people also, and maybe if I should report this somewhere, since I understand crashes can often be used to take control of a victims computer.

A: 

I can replicate your problem using IE8 on Windows 7. It could well be related to this post which suggests that the problem is caused by trying to modify an element before the page has finished loading. If this is the case you can fix the problem by using jQuery to call the loadScript method after the page has finished loading. E.g.

<script>
    $().ready(function() {
        loadScript();
    });
</script>
Phil Hale
Thanks for the suggestion, but no that still crashes the browser...
Peter
Sorry I also should have said you need to comment out the window.onload = loadScript line. The fix I suggested worked when I tried it
Phil Hale
How weird, I tried it (and I did remove the window.onload line), but it still crashed. However, remember that I am not looking for a fix to my code...
Peter
A: 

Try moving the script down to the bottom of the page.

I'd also tidy up the following:

  • Remove the non-html code in the body
  • Add opening & closing html tag

This works for me:

<!doctype html>
<html>
<head>
<title>Crashes IE8 on Win7</title>
<style type="text/css">
article { display: block; }
</style>

</head>
<body>

<div id="map_canvas"></div>

<script type="text/javascript">
document.createElement('article');
document.createElement('nav');

function initialize() {
    var map = new google.maps.Map(document.getElementById("map_canvas"), {});
}

function loadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "http://maps.google.com/maps/api/js?sensor=false&amp;callback=initialize";
    document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</body>
</html>
Space Monkey
Hi Space Monkey. Thanks for your reply. However, I think you misunderstood my reason for posting. I am NOT looking for a fix to my HTML code. I even wrote the fix myself in the original post. I guess you can say my only question was if this crashes IE for other people also. I should have be more clear about that; I am wondering if I should report this somewhere, since crashes are often an entry point for cyberattacks.
Peter
Ah, ooops. Okay, well I can confirm that the original code did crash my IE8. However, I don't feel that this is something that can be reported, as the code itself is intentionally broken.
Space Monkey