编程爱好者之家

js去掉url链接多余参数

2018-12-26 09:16:35 1544

有的时候别人可能会故意刷我们的网站链接,在后面加上参数来访问网站,例如‘http://test.codelovers.cn/?_t=1539913651’我们想实现的效果是自动去掉后缀包含?部分,实现代码如下

if(top != self){
	top.location=self.location;
}else{
	var url = location.search;
	if(url){
		var old_url = window.location.href;
		var new_url = old_url.substring(0, old_url.indexOf('?'));
		self.location = new_url;
	}
}


同类文章