...

View Full Version : Javascript URL redirection



sohail_mubeen
07-06-2011, 03:28 PM
here is the link that i want to redirect http://www.xyz.com/tracks?hop=martitegui&redirection=/special&varname=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.

Philip M
07-06-2011, 04:11 PM
Here you are:-


<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.

sohail_mubeen
07-07-2011, 09:01 AM
Here you are:-


<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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum