Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: open

Message Too Old, No Replies

Javascript Redirect

     

dsook

2:25 pm on May 28, 2008 (gmt 0)

5+ Year Member



I need to use Javascript to redirect and pass the incoming URL parameters to the new website.

For example, a call to:
[mywebsite...] needs to transfer to:

[newwebsite...]

*****************************

I have tried using
<script language="javascript"><!--
location.replace("http://newwebsite/startpage.php)
</script>

This transfers control to the desired webpage, but the parameters are not passed.

*****************************

Thank you in advance for any help you can provide.

Trace

7:57 pm on May 28, 2008 (gmt 0)

10+ Year Member



You need to retrieve the parameters before being able to use them. Here's a general function that I use for doing just that.

function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?"));
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return strReturn;
}

Then you can setup your redirect like this:

<script type="text/javascript">
window.location.href='http://newwebsite/startpage.php?parm1='+getURLParam('parm1')+'&parm2='+getURLParam('parm2')+'&parm3='+getURLParam('parm3');
</script>

Hope that helps and you get it figured out.

dsook

5:30 pm on May 29, 2008 (gmt 0)

5+ Year Member



Thank you very much!

With your help, I now have it working as desired.

--dennis

jianliangwang

11:50 am on May 31, 2008 (gmt 0)

5+ Year Member



Thank you very much!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month