views:

513

answers:

6

In aspx I have a querystring - www.mysite.com/enter.aspx?dest=#. When I click "enter" I go to main.aspx. I want to get this "?dest=#" in main.aspx with a request.querystring or something in javascript. I need to use the querystring in javascript in main.aspx for another action.

Any ideas?

let me explain in detail - I have enter.aspx page that shall load with a querystring - www.mysite.com/enter.aspx?dest=#. Now when i click the Enter button on Enter.aspx page, it shall goto Main.aspx page. When main.aspx page loads i want to write small javascript in main.aspx that shall get the querystring from the previous enter.aspx page and give it an if condition. so if (request.querystring('dest=') > 0 window.open ('a1.jpg') this above code needs to be redesigned so it can work. how can i do this. i tried window.location.href.indexof('dest') , nothing happened.

A: 

To get the current address in javascript you could use window.location.href and test if it contains a given string:

<script type="text/javascript">
if (window.location.href.indexOf('dest=') > 0) {
    window.open('images/newyork.jpg','','') 
}
</script>
Darin Dimitrov
its not picking up anything. how does this code know that the previous screen had a querystring? because i am not opening the new window in previous screen. based on querystring i am opening the window in the next screen. dont i need request.querystring?
window.location.href picks up the current address. You could pass it as parameter.
Darin Dimitrov
+2  A: 
alert(window.location.search); // ?dest=#
Jonathan Sampson
A: 

If you don't have to do this in Javascript, you can always grab the querystring in the codebehind of enter.aspx, then perform a Response.Redirect to main.aspx, appending on the querystring.

Adam V
+1  A: 

This is a bit messy.. YUI has a simple method to get at the querystring response by Gavin Brock.

http://stackoverflow.com/questions/2376517/how-do-you-get-querystring-using-yui-2

giulio
A: 

If you want to get the url from the previous page, you should use "document.referrer".

<script type="text/javascript">
if (document.referrer.indexOf('dest=') > 0) {
    window.open("a1.jpg");
}

shannon.stewart