Created
October 6, 2021 16:59
-
-
Save oliverstech/f27297474eb9ebc4fd25cf1664264a76 to your computer and use it in GitHub Desktop.
Javascript - Redirecting to a domain
This file contains hidden or 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
<html> | |
<script> | |
var path = window.location.pathname; | |
window.location.href = "https//www.example.com" + path; | |
</script> | |
</html> |
This file contains hidden or 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
<!--Here's a demo of what I mean--> | |
<html> | |
<script> | |
// Our js goes here | |
// Store the path in a variable | |
// Example: /wmc | |
var path = window.location.pathname; | |
// Redirect user to website + path | |
// Example: https://www.example.com/wmc | |
window.location.href = "https://www.example.com" + path; // A forward slash isn't needed after the domain. | |
// Example Result: Now, upon visit, the user will be redirected to: 'https://www.example.com/wmc' | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment