Solved

Grabbing the Querysting of a URL in Javascript

Posted on 2008-10-20
4
294 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery delay animation 3 30
javascript: add id amounts 5 47
Scroll 5 news at a time. 4 28
How to display div value on input field value in php 11 28
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

803 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