Created
April 21, 2020 10:09
-
-
Save abhianair/f1751e443f8642cea0769c4bcba8e4f4 to your computer and use it in GitHub Desktop.
jquery url dynamic change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url = window.location.href; | |
| paramName = 'myparam'; | |
| paramValue = $(this).val(); | |
| var pattern = new RegExp('('+paramName+'=).*?(&|$)') | |
| var newUrl = url.replace(pattern,'$1' + paramValue + '$2'); | |
| var n=url.indexOf(paramName); | |
| alert(n) | |
| if(n == -1){ | |
| newUrl = newUrl + (newUrl.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue | |
| } | |
| window.history.pushState('title', active_tab, newUrl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment