0

I want to attach a timestamp to my querystring in order to ensure that the browser bypasses its cache when I refresh the page via javascript. I need to account for an existing querystring (which might already have a timestamp parameter in it) and for the hash tag (http://www.example.com/?ts=123456#example).

I have written my own implementation but I suspect that its unnecessarily complicated. Is there a quick-and-easy or at least elegant way of accomplishing this?

Ken Browning
  • 28,693
  • 6
  • 56
  • 68

2 Answers2

3

For manipulating the query string parameters I recommend you this plugin:

It's very easy to use:

var timestamp = $.query.get('ts'); // get a value

window.location = $.query.set('ts', newValue); // set a value and navigate
Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
0
var newLocation = window.location.href.replace(/\?.*(ts=\d*)/, "ts=" + new Date().valueOf());
NickFitz
  • 34,537
  • 8
  • 43
  • 40