How to replace characters in the current URL using Javascript
During development in one of my project, I need to replace an expression in the URL, the code that helped me is as follows:-
The Steps we will follow are:
1. Get the current URL.
2. Replace the pattern with the required pattern.
3. Redirect to the new URL formed.
var url = window.location.toString();
This will get you the current URL.
url = url.replace(/#popup1/, '');
This will replace the specific pattern with the other pattern provided. In the above case I have replaced '#popup1' with null.
window.location = url;
This will now take you to the new url formed.
Hope it helps... Happy Coding!
0 Comment(s)