Remove plus sign (+) in URL query string

后端 未结 5 1786
失恋的感觉
失恋的感觉 2020-11-29 06:46

I am trying get the string in the following URL to display on my webpage.

http://example.com?ks4day=Friday+September+13th

EDIT: The date in the URL

5条回答
  •  甜味超标
    2020-11-29 07:10

    Parsing strings using regex is often prone to so many errors. Thankfully all modern browsers provide URLSearchParams to handle params from url strings in a proper way:

    var params = new URLSearchParams(window.location.search);
    var value = params.get('ks4day');
    // "Friday September 13th"
    

    Ps: There is also a good polyfill for old browsers.

提交回复
热议问题