I am learning jquery now. I want to replace the parameters of a url with another on page load. For example here is my code
<div class="changeparam">
<a href="http://demo.org/post.php?i=123&p=456&s=789">Link</a>
</div>
Now I need to change the value of the params i,p and s to different values say abc,def,ghi respectively. How can i do it on page load?
Do you need to know the old values? If not can’t you do something along the lines of the following (this assumes the simple case that all links will have the same query string and would need to be extended if this is not the case):
UPDATE:
I’ve created a more flexible function that takes a querystring, an array of items to be replaced and an array of replacement values then outputs a new query string. Have a look at this jsfiddle: http://jsfiddle.net/LWzZR/1
Also, I agree with the commenters on your question – whilst it’s possible, it’s not recommended 🙂