Skip to content

Instantly share code, notes, and snippets.

@motyar
Created September 26, 2014 13:10
Show Gist options
  • Save motyar/b77fae350ee62dd07831 to your computer and use it in GitHub Desktop.
Save motyar/b77fae350ee62dd07831 to your computer and use it in GitHub Desktop.
Redirect to new domain with only JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script>
(function(){
var url = window.location.href;
console.log(url.split('/'));
var newUrl = url.replace(url.split('/')[2],"newdomain.com");
console.log(newUrl);
if(newUrl!=""){//Redirect to github edit
//alert(editUrl);
window.location.href = newUrl;
}
})();
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment