I'd like to have a little easter egg button in the corner of a project site. When clicked, it just drops a string onto the current url and reloads the page.
So if I'm on: http://test.com/projects/view/134
The button is clicked
Page reload on: http://test.com/projects/view/134?ts=true
Not really sure how I might go about doing so though.
I found the previous answers lacking and as such here is a method that better handles other parameters in current querystring
You have to use
location.href = appendToQueryString(ts, true)
to actually reload the page.Using:
Example:
Make full use of the
location
DOM API, and count in hash:try this code,
EDITS: to avoid duplicated parameter or very large string in your url, you need to replace the old param it already exists.
See the documentation of the history API :
https://developer.mozilla.org/en-US/docs/Web/API/History_API
Example of usage:
An improvement from @Bobbzorzen answer, with ability to delete param by passing its name only:
gist: https://gist.github.com/envil/bc1832503bef55ffdabb0cde32bb06f1