append to url and refresh page

amateur picture amateur · May 13, 2011 · Viewed 242k times · Source

I am looking to write a piece of javascript that will append a parameter to the current url and then refresh the page - how can I do this?

Answer

Shlomi Komemi picture Shlomi Komemi · May 13, 2011

this should work (not tested!)

var url = window.location.href;    
if (url.indexOf('?') > -1){
   url += '&param=1'
}else{
   url += '?param=1'
}
window.location.href = url;