Welcome to WebmasterWorld Guest from 54.162.232.51

Forum Moderators: open

Message Too Old, No Replies

Javascript Redirect

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

New User

10+ Year Member

joined:Aug 9, 2006
posts: 2
votes: 0


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.

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

Preferred Member

10+ Year Member

joined:July 5, 2005
posts:352
votes: 0


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.

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

New User

10+ Year Member

joined:Aug 9, 2006
posts: 2
votes: 0


Thank you very much!

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

--dennis

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

New User

5+ Year Member

joined:May 31, 2008
posts:4
votes: 0


Thank you very much!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members