The html code below produces two links that when hovered will output the corresponding audio file. My question is if I have a table of links stored in a Django database how do I output it in the javascript so that using the Django template language I can loop over the table of links to populate the window.onload function? Or is there a more efficient way?
<head>
<script type="text/javascript">
window.onload = function() {
// collecting elements
var welcomeSound = document.getElementById('welcomeSound');
var welcomeTxt = document.getElementById('welcomeTxt');
var sdSound = document.getElementById('shutdownSound');
var sdTxt = document.getElementById('shutdownTxt');
//playing welcome sound on mouse over
welcomeTxt.onmouseover = function() {
welcomeSound.play();
return false;
};
sdTxt.onmouseover = function() {
sdSound.play();
return false;
};
};
</script>
</head>
<html>
<section>
<audio id="welcomeSound" controls="controls" preload="auto">
<source src="welcome.ogg"></source>
Your Browser does not support please use (Firefox 3.5+, Chrome 3+, Opera 10.5+, Safari 4+, IE 9+) browsers.
</audio>
<audio id="shutdownSound" controls="controls" preload="auto">
<source src="shutdown.ogg"></source>
Your Browser does not support please use (Firefox 3.5+, Chrome 3+, Opera 10.5+, Safari 4+, IE 9+) browsers.
</audio>
<p class="info">
Use latest Browser Chrome or FireFox.
<br /> If you usig Internet download manager please close it.
</p>
<a id="welcomeTxt" href="#">
Welcome(Mouse hover here)
</a>
<br />
<br />
<br />
<a id="shutdownTxt" href="#">
Shutdown(Mouse hover here)
</a>
</section>
</html>
{{ }}as you would elsewhere in your template and loop using{% for %}etc.jsfile, short answer seems to be "no". I have seen a few solutions on this site already, but none of them seemed ideal to me, and I have not tried them. However, I have used Django template tags in js within<script></script>tags quite a bit, and have never had issues with it. One thing I have done is put script tags and the enclosed javascript into it's own template, and{% include %}it when I need to use it. That way your script and template are kind of separate, which at least for me helps me focus on one of the other while working.