Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to replace characters in the current URL using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 124
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: