Black
Black

Reputation: 20232

Javascript redirect not working with URL's starting with www

I tried to redirect to www.google.com like this:

    window.location.replace('www.google.com');

However, it does not work. But If I use http or https then it works:

    window.location.replace('http://www.google.com');

But since not every site supports https I always have to insert http to make sure the redirect works for sure.

Upvotes: 0

Views: 53

Answers (1)

yezzz
yezzz

Reputation: 3020

Use urls without protocol:

 window.location.replace('//www.google.com');

Upvotes: 2

Related Questions