append to url and refresh page

后端 未结 11 2237
终归单人心
终归单人心 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 14:58

    Please check the below code :

    /*Get current URL*/    
    var _url = location.href; 
    /*Check if the url already contains ?, if yes append the parameter, else add the parameter*/
    _url = ( _url.indexOf('?') !== -1 ) ? _url+'¶m='+value : _url+'?param='+value;
    /*reload the page */
    window.location.href = _url;
    

提交回复
热议问题