Remove URL parameters without refreshing page

前端 未结 13 1004
执念已碎
执念已碎 2020-12-07 08:00

I am trying to remove everything after the \"?\" in the browser url on document ready.

Here is what I am trying:

jQuery(document).ready(function($)          


        
13条回答
  •  广开言路
    2020-12-07 08:36

    a single line solution :

    history.replaceState && history.replaceState(
      null, '', location.pathname + location.search.replace(/[\?&]my_parameter=[^&]+/, '').replace(/^&/, '?')
    );
    

    credits : https://gist.github.com/simonw/9445b8c24ddfcbb856ec

提交回复
热议问题