-
-
Save parzibyte/264f0e027eea65f05059dfe94d30985e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Abrir cajón de impresora con JavaScript - By Parzibyte</title> | |
</head> | |
<body> | |
<button id="btnAbrirCajon">Abrir cajón</button> | |
<script> | |
document.addEventListener("DOMContentLoaded", () => { | |
const $boton = document.querySelector("#btnAbrirCajon"); | |
/* | |
Cambiar según tus ajustes | |
*/ | |
const nombreImpresora = "ZJ-58", | |
puerto = "8080"; | |
const abrirCajon = async () => { | |
const respuesta = await fetch(`http://localhost:${puerto}/?impresora=${nombreImpresora}`); | |
const respuestaDecodificada = await respuesta.json(); | |
if (respuesta.status === 200) { | |
alert("Cajón abierto"); | |
} else { | |
alert("Error abriendo: " + respuestaDecodificada); | |
} | |
}; | |
$boton.onclick = abrirCajon; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment