Skip to content

Instantly share code, notes, and snippets.

@billyma128
Created May 2, 2017 14:41
Show Gist options
  • Save billyma128/c148039cda3585c5af7509a200501c34 to your computer and use it in GitHub Desktop.
Save billyma128/c148039cda3585c5af7509a200501c34 to your computer and use it in GitHub Desktop.
function wxRefresh() {
    var replaceQueryParam = (param, newval, search) => {
        var regex = new RegExp('([?;&])' + param + '[^&;]*[;&]?');
        var query = search.replace(regex, '$1').replace(/&$/, '');

        return (query.length > 2 ? query + '&' : '?') + (newval ? param + '=' + newval : '');
    };

    window.location.replace(location.protocol +
        '//' +
        location.host +
        location.pathname +
        replaceQueryParam('_wxr_', new Date().getTime(), location.search) +
        location.hash);
};
// 执行
wxRefresh();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment