Reputation: 63
How do I create a URL redirect page as a HTML file, for example, if it was like http://warrenwoodhouse.webs.com/url/?url=linkgoeshere
, as I need it for my page on my website.
The page, when visiting it without a link at the end as http://warrenwoodhouse.webs.com/url/?url=
will not redirect to anything, where as with a link such as http://warrenwoodhouse.webs.com/url/?url=http://youtube.com/user/warrenwoodhouse
will redirect to the specified page in the URL.
If anyone knows the code for HTML and JavaScript, please feel free to leave a comment below.
Upvotes: 0
Views: 150
Reputation: 9964
Try this:-
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var URL = getParameterByName('url');
window.location.href = URL;
Upvotes: 0
Reputation: 1078
I think this can do what you want (found here) :
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
var redirectUrl = getParameterByName('url');
if(redirectUrl != null){
window.location.href = redirectUrl;
}
Upvotes: 3