Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Grabbing the Querysting of a URL in Javascript

Posted on 2008-10-20
4
Medium Priority
?
301 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 2000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

886 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