0

I have this HTML:

<!DOCTYPE html>
<html>
<head>
{% load static %}  
<script type="text/javascript" src="{% static 'js/bundle.js' %}">
<meta charset="utf-8" />
<title>title</title>
</head>
<body>
<p id="url"></p>
</body>
</html>

And the script file:

(async () => {
  ....
  function makeOutput() {
    return 'a url'
  }

  url = makeOutput()
  window.onload = function() {
    document.getElementById("url").innerHTML=url;
  }
  ....
})()

I want to use the url variable in the HTML, but for some reason it isn't letting me save variables the same as as if I were using a script tag with all the code in it.

Any ideas on how to go about this? Thanks

Striped
  • 2,544
  • 3
  • 25
  • 31
Lester
  • 357
  • 3
  • 16
  • There's no difference between the behavior of inline scripts and loaded scripts. Check the Network tab in the Dev Tools to see, if your script was loaded. – Teemu Nov 08 '20 at 10:28
  • I forgot to mention that its inside an async: (async () => { } )() – Lester Nov 08 '20 at 10:30
  • `async` doesn't make any difference, unless the function you want to execute is not placed after `await`, and the awaited promise is never fullfilled. – Teemu Nov 08 '20 at 10:34
  • The problem is caused by a typo. You forgot the end tag for the ` – Quentin Nov 08 '20 at 10:46
  • You sure, sir? If I add a > to it it gives me an error at src... – Lester Nov 08 '20 at 13:15

0 Answers0