[英]Javascript redirect not working with URL's starting with www
I tried to redirect to www.google.com
like this: 我试图这样重定向到www.google.com
:
window.location.replace('www.google.com');
However, it does not work. 但是,它不起作用。 But If I use http
or https
then it works: 但是,如果我使用http
或https
那么它将起作用:
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. 但是由于并非每个站点都支持https,所以我总是必须插入http
以确保重定向能够正常工作。
使用不带协议的网址:
window.location.replace('//www.google.com');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.