简体   繁体   中英

Modify URL and add parameter in between the URL using javascript

I have a long list of urls to be modified.

For example the url is:

 https://somedomain.com/?pid=24787CL22311&source=linkkit&url=https%3A%2F%2Fwww.demo.com 

So in the above url I want to add subid=1233 just before the &source=linkkit

like this:

  https://some.com/?pid=24787CL22311&subid=1233&source=linkkit&url=https%3A%2F%2Fwww.demo.com 

I tried with append, set and replace but did not gave the specific result

Any suggestions ?

You can do something like:

let url = ' https://some.com/?pid=24787CL22311&subid=1233&source=linkkit&url=https%3A%2F%2Fwww.demo.com ';

url = url.replace('&source=', '&subid=1233&source=')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM