This project is a single-file, client-side HTML page designed to perform an immediate URL redirection based on a query parameter. It is useful for creating short, dynamic links or safely redirecting users after an action (like email confirmation) to a custom destination, potentially even using custom URL schemes (like mailto:// or upi://).
The script looks for the value of the url parameter in the current page's query string and immediately navigates the browser to that address.
| Target Action | Example Link |
|---|---|
| Redirect to Youtube | https://pver-programz.github.io/url-redirector/?url=https%3A%2F%2Fwww.youtube.com |
| Open a Mail Client | https://pver-programz.github.io/url-redirector/?url=mailto%3Atest%40example.com |
| Redirect to a Google search | https://yourdomain.com/redirect.html?url=https%3A%2F%2Fgoogle.com/search?q=github |
Note: Always URL-encode the target URL, especially the colon (:) and forward slashes (/), to ensure it is correctly passed and decoded by the browser and the script.
The core logic is handled by the JavaScript function parseAndRedirect() which runs on the page's load event.
- Read Parameter: It uses
new URLSearchParams(window.location.search)to extract the value of theurlparameter. - Decode: It calls
decodeURIComponent(target)to resolve any URL encoding. - Redirect: It sets
window.location.hrefto the decoded URL, causing an immediate browser navigation.
The script includes basic error handling for missing or malformed url parameters.
Use this script with caution, understanding the security implications.