Append to URL and refresh page Ask Question

Append to URL and refresh page Ask Question

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?

ベストアンサー1

Solution:

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

おすすめ記事