Skip to content

Instantly share code, notes, and snippets.

@WilliamsJack
Last active December 28, 2019 11:49
Show Gist options
  • Save WilliamsJack/574eba409fb42115772af05a5cd3f39d to your computer and use it in GitHub Desktop.
Save WilliamsJack/574eba409fb42115772af05a5cd3f39d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JS Insert Test</title>
</head>
<body>
<button id="insert" onclick="insertFunction();">Insert JS</button>
<script>
function insertFunction() {
var html = document.createElement( 'div' );
html.id = 'inserted-html';
html.innerHTML = 'A loop provided by inserted JS will now generate some numbers:'
document.body.appendChild(html);
var script = document.createElement( 'script' );
script.type = 'text/javascript';
script.innerHTML = 'alert("Arbitrary Javascript inserted!");var i;for (i = 0; i < 10; i++) {var e = document.getElementById("inserted-html");var p = document.createElement( "p");p.innerHTML = i;e.appendChild(p);e.appendChild(p);}'
document.head.appendChild(script);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment