Skip to content

Instantly share code, notes, and snippets.

@carlos-jenkins
Created June 8, 2022 02:58
Show Gist options
  • Save carlos-jenkins/215bd192a390861ddce602859461df39 to your computer and use it in GitHub Desktop.
Save carlos-jenkins/215bd192a390861ddce602859461df39 to your computer and use it in GitHub Desktop.
Simple redirect page for domain change with manual link and countdown
<html>
<head>
<title>This domain is gone. Redirecting...</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
font-size: 2em;
text-align: center;
font-family: arial;
}
</style>
</head>
<body>
<div class="content">
<p>The content you're looking for was migrated to a new domain:</p>
<p>
<a id="link"></a>
</p>
<p>You will be redirected in <span id="seconds"></span> seconds ...</p>
</div>
<script>
const newDomain = "https://my.new.domain.com"
const waitTimeMs = 10000
const locationTarget = (
newDomain +
window.location.pathname +
window.location.search
)
let timeLeft = waitTimeMs / 1000
// Update UI
document.getElementById("link").innerHTML = locationTarget;
document.getElementById("link").href = locationTarget;
document.getElementById("seconds").innerHTML = timeLeft;
// Countdown
setInterval(function() {
timeLeft -= 1
if (timeLeft > 0) {
document.getElementById("seconds").innerHTML = timeLeft;
}
}, 1000)
// Timed redirect
setTimeout(function() {
window.location.href = locationTarget
}, waitTimeMs)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment