Remove URL parameters without refreshing page

前端 未结 13 964
执念已碎
执念已碎 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

    0 讨论(0)
提交回复
热议问题