我有以下网址:
http://www.sampleurl.com/entrant-entry?entry=ca2f346b12cabcf2626b81c6900500ff
我需要获取entry
的值,在这种情况下为ca2f346b12cabcf2626b81c6900500ff
,并将其附加到目标URL的末尾:
http://ugc-4vets4life.market-online.net/voter-entry?entry=ca2f346b12cabcf2626b81c6900500ff
我查看了几个答案,但似乎没有一个清楚的答案。我需要在JavaScript中执行此操作。
答案 0 :(得分:2)
类似这样的东西:
var url_string = "http://www.sampleurl.com/entrant-entry?entry=ca2f346b12cabcf2626b81c6900500ff";
var voter_url_string = "http://ugc-4vets4life.market-online.net/voter-entry?entry=";
var url = new URL(url_string);
var entry = url.searchParams.get("entry");
var final_url_string = voter_url_string + entry;
console.log(final_url_string);