Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Javascript URL redirection

    here is the link that i want to redirect http://www.xyz.com/tracks?hop=martit...e=1&varname2=2

    when it will redirect the URL will be
    http://www.xyz.com/special?varname1=1&varname2=2

    it's mean the hop and redirection variable will be remove from querystring, special is a page, it will take value from redirection variable, nothing will be hardcode.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Here you are:-

    Code:
    <script type = "text/javascript">
    
    var link = "http://www.xyz.com/tracks?hop=martitegui&redirection=/special&varname1=1&varname2=2"
    var newlink = link.replace(/(special\&)/i,"special?");
    newlink = newlink.replace(/(\.com.*=\/)/, ".com/");
    
    document.write (newlink + "<br>");  //  http://www.xyz.com/special?varname1=1&varname2=2
    
    
    </script>

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Here you are:-

    Code:
    <script type = "text/javascript">
    
    var link = "http://www.xyz.com/tracks?hop=martitegui&redirection=/special&varname1=1&varname2=2"
    var newlink = link.replace(/(special\&)/i,"special?");
    newlink = newlink.replace(/(\.com.*=\/)/, ".com/");
    
    document.write (newlink + "<br>");  //  http://www.xyz.com/special?varname1=1&varname2=2
    
    
    </script>

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." — Jamie Zawinski.
    i have describe before no thing will be hardcoded here you do
    var newlink = link.replace(/(special\&)/i,"special?");
    we will get the value from redirection=/special mean "/special" is our value there may be come some things so we first get the value from redirection variable.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •