Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript changing the get parameter without redirecting [duplicate]

How can I just change the get parameter without redirecting?

parent.location.search = "?after=20"; 
// ok that changes, but also redirect to the new page

Any solution? Or answer is no, if its no, please write big no.

like image 982
Basit Avatar asked Sep 28 '09 17:09

Basit


2 Answers

Update

Since this is the accepted answer, and no longer true, refer to this duplicate question for up to date information.

Original answer follows:


NO

You can come close with the anchor portion of the URL which is accessible by the hash property of the location object

parent.location.hash = "whatever value you want";
like image 118
Peter Bailey Avatar answered Oct 25 '22 02:10

Peter Bailey


If your aim is to use the query string to store some state that can later be restored from a bookmark, you should use anchors instead.

However, if you must change the query string for some reason, actually there is a way. However, I don't endorse this. I'm just mentioning it for completeness.

When a server returns a 204 No Content response, most browsers won't do anything -- i.e. won't even attempt to transition to another page or even wipe the current page. What you can do is to make the backend just emit a 204 response when a request is made to the same page that was just served, with a change in the query parameters.

like image 45
Ates Goral Avatar answered Oct 25 '22 04:10

Ates Goral