It's not a duplicate question because I'm asking why, not how
If I paste everything between the <script></script>
into the chrome console and press enter, it works perfectly, but when I load it with html, it doesn't work, why?
<!DOCTYPE html>
<html>
<head></head>
<body></body>
<script>
toClipboard('Hello World!');
function toClipboard(someText) {
//This function copies some text into your clipboard.
//It's an ugly workaround, because there's no built-in function in JS that does this job.
var temp = document.createElement('input');
document.body.appendChild(temp);
temp.value = someText;
temp.select();
document.execCommand('copy');
document.body.removeChild(temp);
console.log('"' + someText + '" should have been copied to your clipboard');
}
</script>
</html>