Remove URL parameters without refreshing page

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

    These are all misleading, you never want to add to the browser history unless you want to go to a different page in a single page app. If you want to remove the parameters without a change in the page, you must use:

    window.history.replaceState(null, null, window.location.pathname);
    

提交回复
热议问题