Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Grabbing the Querysting of a URL in Javascript

Posted on 2008-10-20
4
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

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…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

670 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