Reputation: 6648
If an URL contains the word "hello", then remove "hello" from the URL and redirect. How is that possible? Example:
On page load, I want to check if "hello" is found, and then do a:
window.location.href = 'http://www.google.com';
Thanks in advance
Upvotes: 1
Views: 1058
Reputation: 30135
No need for jquery here:
window.onload = function(){
if(location.href.indexOf('hello') > -1){
location.href = location.href.replace(/hello/,'www');
}
};
Upvotes: 2
Reputation: 780724
if (url.match(/hello/)) {
window.location.href = url.replace(/hello/, 'www');
}
Upvotes: 1