On my site, I want to search/replace for all instances of one URL (that has different IDs, otherwise it is the same) to another.
For example, my site could have the following hyperlinked URLs (they are just examples, again, the IDs will be different):
- https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=7
- https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=35
- https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=100
- https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=9434
and so I would want the new URLs to be
- https://example.com/Lists/Your%20Col/Item/editifs.aspx?ID=7&Source=https://example.com/Lists/Your%20Col/AO12.aspx&DefaultView=AO
- https://example.com/Lists/Your%20Col/Item/editifs.aspx?ID=35&Source=https://example.com/Lists/Your%20Col/AO12.aspx&DefaultView=AO
- https://example.com/Lists/Your%20Col/Item/editifs.aspx?ID=100&Source=https://example.com/Lists/Your%20Col/AO12.aspx&DefaultView=AO
- https://example.com/Lists/Your%20Col/Item/editifs.aspx?ID=9434&Source=https://example.com/Lists/Your%20Col/AO12.aspx&DefaultView=AO
I am using the following JavaScript code to achieve what I want in the HTML that follows, but it's not working. What am I doing wrong? How can the code be updated so the desired result is achieved?
<script type="text/javascript">
const old_url = "https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=14";
const searchParams = new URLSearchParams(old_url);
const ID = searchParams.get("ID");
const new_url = `https://example.com/Lists/Your%20Col/Item/editifs.aspx?ID=${ID}&Source=https://example.com/Lists/Your%20Col/AO12.aspx&DefaultView=AO`;
console.log(new_url);
</script>
<html>
<a href="https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=7">This is a link</a>
<a href="https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=35">This is a link</a>
<a href="https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=100">This is a link</a>
<a href="https://example.com/_layouts/15/listform.aspx?PageType=6&ListId=%7B6DDF7ABCX%2D5A27%2D4BEB%2DB4F9%2D158FAA3F0B34%7D&ID=9434">This is a link</a>
</html>