View Full Version : Passing query string through a page
elcaro2k
09-18-2002, 01:26 PM
Can someone tell me the best way to pass a query string through an intermediate page on to the next page? In other words I call a page with a query string in the url and at that point I call another page and I would like to keep the string in tact and pass it to the next page.
Thanks,
Ray
Alekz
09-18-2002, 03:05 PM
Hi,
If Your location is: http://blah.com/page1.html?x=12
newPage = http://blah.com/page2.html;
newURL = newPage + '?' + document.location.search;
should produce http://blah.com/page2.html?x=12 (or something similar - too lazy to check the exact syntax right now)...
Alex
ShriekForth
09-18-2002, 03:16 PM
You could parse the intermediate page location, and get the query string, then append it to the link to the last page.
parse.html
<script type="text/javascript" language="JavaScript">
function getString(){
var str = new String(document.location);
vars = str.split("?");
if (vars.length == 2)
return "?"+vars[1];
else //
return "";
}
</script>
<script type="text/javascript" language="JavaScript">
document.writeln("<a href='http://www.yahoo.com/"+getString()+"'>Next Page</a>");
</script>
<br><a href="parse.html?me=mine&isnot=here">Here</a>
That should give you some idea. I just put there Here link to give it something to parse. It would work just as well if it were coming to parse.html.
ShriekForth
beetle
09-18-2002, 03:49 PM
Originally posted by Alekz
Hi,
If Your location is: http://blah.com/page1.html?x=12
newPage = http://blah.com/page2.html;
newURL = newPage + '?' + document.location.search;
should produce http://blah.com/page2.html?x=12 (or something similar - too lazy to check the exact syntax right now)...
Alex Close. First off, location is a sub-object to window not document. 2nd, location.search already includes the '?', so it needs not appending here.
newURL = newPage + location.search;
elcaro2k
09-18-2002, 06:11 PM
OK, I am confused. If I do a document.write(location.search) I get nothing, however, if I use vbScript and do a response.write(Request.Form()), I print out the query string? Why can I not see it in JS?
btw, the reason I was printing it out is because the target page was not receiving the string.
ShriekForth
09-18-2002, 06:18 PM
The above assumes a form method GET, not a POST, if it is a post, you will have to have the server pass back the information posted.
ShriekForth
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.