How To Make Html Call A Javascript Function From An External Js File, In Django Environment
I am developing an app with Django. I want an alert window pops up as soon as the user lands on a certain HTML page. The javascript function that makes the window pop up is called
Solution 1:
In the external javascript file at path
static/js/prova.js
insert
function funprova() {
alert("Hello! I am an alert box from remote js file!!");
}
In the HTML page that has to pop up the window, before of the closing </body>
tag, insert
{% load static %}
<script type="text/javascript" src={% static "js/prova.js" %}></script>
<script> funprova() </script>
Note: You have to call javascript in two differents script tags, because in the former you make the call to a function stored an external file, while in the latter you call a function that was already imported into the HTML file environment.
Note: It is better to insert the {% load static %}
Django tag at the very top of your HTML page, before the HTML tag.
Post a Comment for "How To Make Html Call A Javascript Function From An External Js File, In Django Environment"