append to url and refresh page

后端 未结 11 2202
终归单人心
终归单人心 2020-12-07 14:07

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?

11条回答
  •  离开以前
    2020-12-07 15:06

    Shorter than the accepted answer, doing the same, but keeping it simple:

    window.location.search += '¶m=42';
    

    We don't have to alter the entire url, just the query string, known as the search attribute of location.

    When you are assigning a value to the search attribute, the question mark is automatically inserted by the browser and the page is reloaded.

提交回复
热议问题