Javascript redirect example
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 name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Form Redirect</title> | |
</head> | |
<body> | |
<h1>Luiz Cloud</h1> | |
<form id="domain-redirect"> | |
<div> | |
<input type="text" name="domain" id="domain" />.luiz.com.br | |
</div> | |
<div> | |
<input type="submit" value="Acessar Meu Domínio" /> | |
</div> | |
</form> | |
<script> | |
// Obtenho o formulário | |
const form = document.getElementById('domain-redirect') | |
// Fico escutando quando ele for submetido | |
form.addEventListener('submit', function(e) { | |
// Previno o comportamento padrão que é fazer o GET ou POST | |
e.preventDefault() | |
// Obtenho o valor do campo domain | |
const domain = document.getElementById('domain').value | |
// Faço o redirect | |
window.location.href = `https://${domain}.luiz.com.br` | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment