Skip to content

Instantly share code, notes, and snippets.

@softplus
Last active April 23, 2021 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softplus/28ab8b3357c240786c1fc10229ced529 to your computer and use it in GitHub Desktop.
Save softplus/28ab8b3357c240786c1fc10229ced529 to your computer and use it in GitHub Desktop.
Nofollow bounce page (Markdown, HTML, JS)
Click here to follow this link:
<span id="redirect"></span>
<script type="text/javascript">
// Take any URL after the # and redirect to it, if the referrer is local.
// For visitors without a local referrer, just display the link and let them click.
let target = document.location.hash.substring(1);
if (target && (target.startsWith("http://") || target.startsWith("https://"))) {
if (document.referrer.startsWith(document.location.origin)) {
// we can redirect
document.location=target;
} else {
// just display the link
let el = document.createElement("a");
el.href = target;
el.rel = "nofollow";
el.className = "external";
el.target = "_blank";
el.appendChild(document.createTextNode(target));
document.getElementById("redirect").appendChild(el);
}
} else {
// no target
document.getElementById("redirect").innerHTML = "none";
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment