KittenKatja
Well-Known Coder
These questions are related to one overarching topic (the title) and I'd like them all to be answered. (not hand-picked like my previous topics)
How do I take the video/audio controls from the video/audio elements and put them somewhere else?
I'd also like to write their values into a cookie, so I can fetch the last selected option, or the last set volume settings, and apply them on reload.
HTML:
<html>
<body>
<span>Background: <input id="bg_volume" type="range" style="width: 300px;" onchange="setCookie('bg_volume',this.value,3)"> <a onclick="toggleSound('background')">Off</a></span>
<span>Media: <input id="md_volume" type="range" style="width: 300px;" onchange="setCookie('md_volume',this.value,3)"> <a onclick="toggleSound('media')">Off</a></span>
<span>Master: <input id="mst_volume" type="range" style="width: 300px;" onchange="setCookie('mst_volume',this.value,3)"> <a onclick="toggleSound('master')">Off</a></span>
<audio id="media" loop controls></audio>
<video id="background" loop muted></video>
</body onload="loadSetup()">
</html>
JavaScript:
function setBackground(url) {document.getElementById("background").src=url;setCookie("background", url, 3);setSelected()}
function setCookie(cname, cvalue, exdays) {const d = new Date();d.setTime(d.getTime() + (exdays*24*60*60*1000));let expire = "expires="+ d.toUTCString();document.cookie = cname + "=" + cvalue + ";" + expire + ";path=/";}
function getCookie(cname, cfallback) {let n = cname + "=";let dc = decodeURIComponent(document.cookie);let ca = dc.split(';');for(let i = 0; i <ca.length; i++) {let c = ca[i];while (c.charAt(0) == ' ') {c = c.substring(i);} if (c.indexOf(n) == 0) {return c.substring(n.length, c.length);}} return cfallback;}
function loadSetup() {setBackground(getCookie("background","file:///..."))}
I'd also like to write their values into a cookie, so I can fetch the last selected option, or the last set volume settings, and apply them on reload.
If it's possible to write a download prompt, can I also set a suggestion file name?