Solved

Grabbing the Querysting of a URL in Javascript

Posted on 2008-10-20
4
295 Views
Last Modified: 2012-06-21
Hi there I have a javascript call to a reload on my page.

<script type="text/javascript">
parent.location.reload("finish.asp?UserId=")
</script>

I need to append finish.asp in the code above with the UserId from the previous page. I am passing the userId in the URL like this

Response.Redirect("finish3.asp?ID=" & intNewId)

Can anyone help please?
0
Comment
Question by:MayoorPatel
  • 2
4 Comments
 
LVL 7

Expert Comment

by:dctuck
ID: 22758741
You have to manually parse the window.location property to find any query string parameters. Alternatively, if you don't feel like writing all the extra code yourself, there are some javascript libraries already written to do so. Here's an example library:
http://andrewu.co.uk/tools/request/
 
0
 
LVL 15

Expert Comment

by:MMDeveloper
ID: 22758761
0
 
LVL 7

Expert Comment

by:dctuck
ID: 22758880
I've just put together this very basic script - you just need to pass the Querystring parameter name you want to find the value for to the QueryString function, and it will return the value
function QueryString(item) {
    // Get the value of the key/value pair in the document URL
    var href = window.location.search;
    if (href == "") {
        return null;
    }
    href = href.substring(1);
    var items = href.split("&");
    for (var i = 0; i < items.length; i++) {
        var keyValue = items[i].split("=");
        if (keyValue[0] == item) {
            return keyValue[1];
        }
    }
    return null;
}

Open in new window

0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22760148
>>I am passing the userId in the URL like this: Response.Redirect("finish3.asp?ID=" & intNewId)
OK, then if you already have the id in an asp variable, instead of:
<script type="text/javascript">
parent.location.reload("finish.asp?UserId=") 
</script> 
try:
<script type="text/javascript">
parent.location.href="finish.asp?UserId=<%=intNewId%>&cacheBuster=" + new Date();
</script>

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Add shadow behind div 5 25
jQuery Toggle & Anchor Links 5 43
How to control cache of some js files ? 7 41
Can't get page to reload 9 12
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question