Last active
July 26, 2021 18:47
-
-
Save Arsfiqball/8b5eb59111aee7aa9e01ffe7d3046b19 to your computer and use it in GitHub Desktop.
Run javascript from a html textarea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Run Script</title> | |
</head> | |
<body> | |
<textarea id="code">return 1 + 4</textarea> | |
<button onclick="run()">Run</button> | |
<pre id="result"></pre> | |
<script> | |
function run () { | |
const code = document.getElementById('code').value | |
const resultEl = document.getElementById('result') | |
const fn = new Function(code) | |
resultEl.innerHTML = fn() | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment