Skip to content

Instantly share code, notes, and snippets.

@andrewagain
Created September 29, 2015 19:19
Show Gist options
  • Save andrewagain/a28a47f1364dfac1f98b to your computer and use it in GitHub Desktop.
Save andrewagain/a28a47f1364dfac1f98b to your computer and use it in GitHub Desktop.
<head>
<script type='text/javascript'>
console.log('main-tag');
document.write('<script type=\"text/javascript\" src="http://cdn.ahf.io/remote.js"><\/scr'+'ipt>');
</script>
</head>
<body>
Body
<script type='text/javascript'>
console.log('end-of-body-tag');
</script>
</body>
<head>
<script type='text/javascript'>
console.log('main-tag');
var head = document.getElementsByTagName('head').item(0);
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'http://cdn.ahf.io/remote.js');
head.appendChild(script);
</script>
</head>
<body>
Body
<script type='text/javascript'>
console.log('end-of-body-tag');
</script>
</body>
console.log('remote-tag');
@andrewagain
Copy link
Author

I believe adding a script tag with document.write causes it to run immediately.

Run the 2 HTML files and look at the console.

nodeadd.html output:

main-tag
end-of-body-tag
remote-tag

docwrite.html output:

main-tag
remote-tag
end-of-body-tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment