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.
I use this code snippit in my personal projects where i need to remove URL params without re-loading:
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.
I have faced the same problem. My solution was these: Get the request like this:
After finishing the operation redirect like this:
In the response, if there is any message, I print them like this:
I hope it will help others :)
Updated Code Now it will work
Just Add Below code in you page whose link you want to change.
Don't forget to add http://code.jquery.com/jquery-latest.js on your page
You could avoid a query string altogether by using
POST
instead ofGET
.That is achievable in modern browsers using the history api, but probably isn't the best solution to your problem.
It sounds like you would be better off processing the data and then redirecting to the homepage instead of returning an HTML document directly.
Since you aren't wanting to keep the URL around, it won't be useful for bookmarking, so it is quite likely you would be better off making a POST request.
This suggests that you should be using the POST-Redirect-GET pattern.