didsun didsun - 2 months ago 6
Javascript Question

JavaScript remove parameter from URL

I want to remove parameter from URL.
I have this URL http://localhost/?page=test&id=190603|190629

<button onclick="removeId(190603)">Remove ID</button>
<button onclick="removeId(190629)">Remove ID</button>


How to do when click on button that id be removed from the url address and reload address without ID I've removed?

Answer

Just trying... (this was for prev version of question)

s=location.search||$('tag').text();
s=s.match(/id=([\d|]*)/)[1];
if(s)
s.split('|').forEach(function(e){
document.write('<a href=http://localhost/?page=test&id='+s.replace(new RegExp('(^|[|])'+e+'(?=$|[|])'),'')+'">Remove '+e+' id from url</a><br>')
});
location.search=<tag color="red">?page=test&amp;id=190603|764583|87436835|846345</tag><br>

Okay, i got some lulz.

Ow, and answer for updated question: Make the same (as above) thing on php