Acción | Comando |
---|---|
Atras | history.go(-1); |
Bucle: forEach |
Object.keys(obj).forEach(function(key,index) { // key: the name of the object key // index: the ordinal position of the key within the object }); |
Error: No module.... | <script> type="module" |
Exportar a PDF | <script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"
integrity="sha512-GsLlZN/3F2ErC5ifS5QtgpiJtWd43JWSuIgh7mbzZ8zBps+dvLusV+eNQATqgA/HdeKFVgA5v3S/cIrLF7QnIg=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
var element = document.getElementsByTagName('html'); html2pdf(element[0]); |
Fichero, leer |
var request = new XMLHttpRequest(); request.open("GET", "./myfile.txt", false); request.send(null); var returnValue = request.responseText; |
Incluir html en html |
function includeHTML() { elmnt = document.getElementById('w3-include-html') file = elmnt.getAttribute("w3-include-html"); if (file) { xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4) { if (this.status == 200) { elmnt.innerHTML = this.responseText; } if (this.status == 404) { elmnt.innerHTML = "Page not found."; } } }; xhttp.open("GET", file, true); xhttp.send(); } } includeHTML();En html incluimos: <div w3-include-html="/cabecera.html"></div> <script src="/js/include.js"></script> |
select |
sel = document.querySelector('#select') sel.onclick = (event) => { event.preventDefault() alert(sel.value); }; |