Remove URL parameters without refreshing page

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

    Here is an ES6 one liner which preserves the location hash and does not pollute browser history by using replaceState:

    (l=>{window.history.replaceState({},'',l.pathname+l.hash)})(location)
    

提交回复
热议问题