Reputation: 21345
I am trying to replace the visited URL with another URL whenever certain search terms are used.
However browsing bing.com for the term "foobar"
results in the URL bing.com/www.google.com.au
instead of just google.com.au
.
I have tried using both location.href
and location.replace()
:
var OldUrl = location.href
var NewUrl = "www.google.com.au";
var arr = ["foobar"];
for (var i = 0, len = arr.length; i < len; ++i) {
if (OldUrl.indexOf(arr[i]) != -1) {
// str contains arr[i]
location.href = NewUrl;
//location.replace(NewUrl);
found = true;
break;
}
}
Upvotes: 0
Views: 379
Reputation: 7573
URLs are treated as relative unless prefixed with a protocol. To solve your issue in particular, I'd suggest
var NewUrl = 'https://www.google.com.au'
Upvotes: 1