Change URL parameters

前端 未结 26 2213
孤独总比滥情好
孤独总比滥情好 2020-11-22 08:40

I have this URL:

site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc

what I need is to be able to

26条回答
  •  醉酒成梦
    2020-11-22 09:21

    A modern approach to this is to use native standard based URLSearchParams. It's supported by all major browsers, except for IE where they're polyfills available

    const paramsString = "site.fwx?position=1&archiveid=5000&columns=5&rows=20&sorting=ModifiedTimeAsc"
    const searchParams = new URLSearchParams(paramsString);
    searchParams.set('rows', 10);
    console.log(searchParams.toString()); // return modified string.
    

提交回复
热议问题