Search code examples
javascriptjqueryrefresh

Append to URL and refresh page


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?


Solution

  • Solution:

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