KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there a way to load and execute a javascript file in a synchronous way just like a synchronous XMLHttpRequest? I'm currently using a sync XMLHttpRequest and then eval for this, but debugging that code is very difficult... Thanks for your help! Update I tried this now: test.html <html> <head> <script type="text/javascript"> var s = document.createElement("script"); s.setAttribute("src","script.js"); document.head.appendChild(s); console.log("done"); </script> </head> <body> </body> </html> script.js console.log("Hi"); Output: done Hi So it was not executed synchronously. Any idea to make "Hi" appear first? Update 2 Other example test.html (code inside a script tag) var s = document.createElement("script"); s.setAttribute("src","script.js"); document.head.appendChild(s); SayHi(); script.js function SayHi(){ console.log("hi"); } Output: Uncaught ReferenceError: SayHi is not defined
Tags (comma-separated)
Save Edits
Cancel