Using location.search to locate a parameter's value

前端 未结 4 1560
走了就别回头了
走了就别回头了 2021-02-09 16:05

I’m working on a tool which takes the value parameters in the URL and does a few things with them.

My issue is, I can’t seem to use document.location to show the specifi

4条回答
  •  臣服心动
    2021-02-09 16:32

    To make ?yourname=gilgilad using document.location.search:

    window.location.search = 'yourname=gilgilad';
    

    here is jsfiddle: http://jsfiddle.net/t81k3bgc/

    make sure to use console and then [run]. you will see: enter image description here

    For more information: https://developer.mozilla.org/en-US/docs/Web/API/Window.location#Example_.235.3A_Send_a_string_of_data_to_the_server_by_modifying_the_search_property.3A

提交回复
热议问题