Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Javascript redirect example
<!DOCTYPE html>
<html lang="en">
<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>
<h1>Luiz Cloud</h1>
<form id="domain-redirect">
<input type="text" name="domain" id="domain" />
<input type="submit" value="Acessar Meu Domínio" />
// 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
// Obtenho o valor do campo domain
const domain = document.getElementById('domain').value
// Faço o redirect
window.location.href = `https://${domain}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment