我有以下一段代码,它在某种程度上是可行的。
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
var sanitized = url
.replace(/^https\:\/\//, '') // remove the leading http:// (temporarily)
.replace(/\/+/g, '/') // replace consecutive slashes with a single slash
.replace(/\/+$/, ''); // remove trailing slashes
url = 'https://' + sanitized;
window.onload = function urlChange(){
location.replace(url);
}
唯一的问题是,一旦URL更改,页面就像我有一个无限循环一样不断重新加载。
有任何想法吗?
谢谢!