How to remove query string from url using javascri

2019-09-18 11:50发布

问题:

I have one page when which have a query string like http://www.test.com/mypage?abc=xyz

I want only page URL after loading in browser, but my query string will not be removed. e.g. http://www.test.com/mypage.

I need query string each and every time. I don't want to visualize to user.

回答1:

Eventually you still need to send the request with those query string, so I assume you are asking to hide it in the address bar. I suggest go with create a big 100% height/width iframe to link to your detail page and then user will not able to see the query string in the address bar directly as it's in the iframe



回答2:

The only way to do it is with a new HTML 5 feature on the history object:

window.history.replaceState(“Replace”, “Page Title”, “/mypage”);

Otherwise you'll need to use POST or reload the page with cookies to hide the query parameters.