<head></head><head></head><body onload="test()"> <pre>Script failed to run.</pre> <script> function test() { alert(document.getElementsByTagName('PRE')[0].firstChild.data = document.documentElement.innerHTML); } var head1 = document.createElement('head'); document.documentElement.insertBefore(head1, document.documentElement.firstChild); // var head2 = document.createElement('head'); // document.documentElement.appendChild(head2); // document.documentElement.appendChild(document.body); </script> </body>