How to append query parameter at runtime using jQuery
- by Wondering
Through JavaScript I am appending one query parameter to the page url and I am facing one strange behaiviour.
<div>
<a href="Default3.aspx?id=2">Click me</a>
</div>
$(function () {
window.location.href = window.location.href + "&q=" + "aa";
});
Now I am appending &q=aa in default3.aspx and in this page the &q=aa is getting added continuously, causing the URL to become:
http://localhost:1112/WebSite2/Default3.aspx?id=2&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa&q=aa
One would say just pass it like <a href="Default3.aspx?id=2&q=aa">Click me</a>, but I cant do that. The value of this query parameter is actually the value of an HTML element which is in default3.aspx. I have to add it in runtime.
What are the ways to achieve this?