0

I'm trying to get js code from somewhere else and run it But it did not run after loading

Does anyone know how to run? (Code here)

thanks

<html>
<head>
</head>
<body>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.async = true;
    script.src = 'http://localhost/check.js';
    document.getElementsByTagName('head')[0].appendChild(script);
}
</script>

</body>
</html>

js page:

alert("work?");
  • Possible duplicate of [document.createElement("script") synchronously](https://stackoverflow.com/questions/3248384/document-createelementscript-synchronously) – Round-Sliced Apr 07 '18 at 20:10

1 Answers1

0

You created http server, which listening 80 port? localhost using if local server, if you want to load local file - use path for file (not for server localhost).

Artem
  • 71
  • 4