如何在页面加载后从URL中删除查询字符串? [英] How can I remove the query string from the url after the page loads?

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

问题描述

我有一个附加了长查询字符串的URL。
页面加载后,我不需要查询字符串。所以我想从地址栏中删除查询字符串而不重新加载页面。



我试过 parent.location.hash =''; window.location.href ='/#'



他们没有制作一个差异。

解决方案

如果不重新加载页面就不能这样做,想象一下你是否可以在浏览器地址中放置任何你想要的东西酒吧?安全乐趣:)



虽然现在可以使用新的历史API ,但实际上,您的方案最好保证重写而不是包括那些(似乎是大锤要破解坚果)。 / p>

如你所说,在页面加载后你不需要查询字符串,你应该真的回发,然后在你之后重定向到另一个URL已完成处理。


I have a URL with a long query string attached to it. After the page loads, I do not require the query string. So I want to remove the query string from the address bar without a page reload.

I tried parent.location.hash = ''; and window.location.href = '/#'

They did not make a difference.

解决方案

You can't do that without reloading the page, imagine if you could put whatever you wanted in the browser address bar? Security fun :)

Although you can now do it in HTML5 (which will only work on browsers supporting it) using the new history API, but realistically, your scenario best warrants a rewrite instead of including that (seems sledgehammer to crack a nut).

As you said you don't need the query string after the page loads, you should really post back, then redirected to another URL after you've finished your processing.

这篇关于如何在页面加载后从URL中删除查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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