homepage Welcome to WebmasterWorld Guest from 54.197.111.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript Redirect
dsook




msg:3660910
 2:25 pm on May 28, 2008 (gmt 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.

 

Trace




msg:3661267
 7:57 pm on May 28, 2008 (gmt 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.

dsook




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

Thank you very much!

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

--dennis

jianliangwang




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

Thank you very much!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved