js去掉url链接多余参数

2019-01-24 16:41:06 3311

有的时候别人可能会故意刷我们的网站链接,在后面加上参数来访问网站,例如‘http://www.landui.com/?_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;

}

}


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: