Solved

Grabbing the Querysting of a URL in Javascript

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now