如何使用javascript从url中删除查询字符串 [英] How to remove query string from url using javascript

查看:42
本文介绍了如何使用javascript从url中删除查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中有一个查询字符串,如 http://www.test.com/mypage?abc=xyz

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

在浏览器中加载后我只想要页面 URL,但我的查询字符串不会被删除.例如http://www.test.com/mypage.

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.

推荐答案

唯一的方法是在历史对象上使用新的 HTML 5 功能:

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

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

否则,您将需要使用 POST 或使用 cookie 重新加载页面以隐藏查询参数.

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

这篇关于如何使用javascript从url中删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆