Last active
May 23, 2022 04:55
-
-
Save yeyuguo/82aee0f82b393c4eaebbc39a5bb2a91a to your computer and use it in GitHub Desktop.
不刷新页面,清除url参数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 不刷新页面, 清除 url 参数 */ | |
function clearAutoParams(name) { | |
try { | |
// 获取正则结果 | |
const getRegRes = function(name) { | |
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); | |
var result = window.location.search.substr(1).match(reg); | |
return result | |
} | |
const result = getRegRes(name) | |
if(result && result.length) { | |
if(history && history.replaceState) { | |
history.replaceState("", "去除自动领取参数", location.href.replace(result[0],'')) | |
} | |
} | |
} catch (error) { | |
console.log('error: ', error); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 清除登陆自动领取参数, 但不刷新页面 | |
// 使用 vue 的 $route.query.xxx = '' 置空无效 | |
// todo 有bug问题: pushState 会更新历史记录,如果返回上一页是无法做到的; | |
// 应该使用 replaceState,其他都一样,只是不会更新 历史记录; https://blog.csdn.net/drothyChild/article/details/78849852 | |
function clearAutoParams(name) { | |
// 获取正则结果 | |
const getRegRes = function(name) { | |
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); | |
var result = window.location.search.substr(1).match(reg); | |
return result | |
} | |
const result = getRegRes(name) | |
if(result && result.length) { | |
if(history && history.pushState) { | |
history.pushState("", "去除自动领取参数", location.href.replace(result[0],'')) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
todo 有bug问题: pushState 会更新历史记录,如果返回上一页是无法做到的;
应该使用 replaceState,其他都一样,只是不会更新 历史记录; https://blog.csdn.net/drothyChild/article/details/78849852