Is there a plugin-less way of retrieving query string values via jQuery (or without)?
If so, how? If not, is there a plugin which can do so?
Is there a plugin-less way of retrieving query string values via jQuery (or without)? If so, how? If not, is there a plugin which can do so? |
|||||||||||||||||
locked by animuson♦ Jul 25 '14 at 19:35This question's answers are a collaborative effort: if you see something that can be improved, just edit the answer to improve it! No additional answers can be added here |
|||||||||||||||||
|
If you are using Browserify, you can use the
Further reading: URL Node.js v0.12.2 Manual & Documentation |
|||||||||
|
Code:
How to Call:
Output:
|
||||
|
One line code to get Query
|
|||||||||
|
Here is my version of query string parsing code on github It's "prefixed" with jquery.*, but the parsing function itself don't use jQuery. Its pretty fast but still open for few simple performance optimizations. Also it supports list & hash-tables encoding in URL, like:
or
|
||||
|
Here's what I'm using:
Returning 'override' rather than '0' in the last case makes it consistent with PHP. Works in IE7. |
|||||||||
|
For those who wants a short method (with limitations):
|
|||||||||||||
|
Get all querystring parameters including checkbox values (arrays). Considering the a correct & normal use of GET parameters the things i see it's missing, on most functions, is the support for arrays and removing the hash data So i wrote this function
Using shorthand operators & while-- loop the performance should be very good to. Support:
Notes: It does not support object arrays (key[key]=value) If the space is + it remains a +. add Usage:
Return:
Demo: Info If you don't understand something or you can't read the function just ask i'm happy to explain what i did here. If you think the function is unreadable and unmanainable i'm happy to rewrite the function for you , but consider that shorthand & bitwise operators are always faster than a standard syntax (mybe read about shorthands and bitwise operators in the ECMA-262 book or us your favorite searchengine).Rewriting the code in a standard readable syntax means performance loss. |
||||
|
|
||||
|
This one works fine
taken from here |
|||||
|
I would rather use split() instead of Regex for this operation:
|
||||
|
A very lightweight jquery method:
And to alert ,for example ?q
|
|||||
|
Try this:
Then call it like so:
You can use this for cookies also:
This only works for strings that have "key=value[&|;|$]"... will not work on objects/arrays. If you don't want to use String.prototype... move it to a function and pass the string as an argument |
||||
|
Here's my own take on this. This first function decodes a URL string into an object of name/value pairs:
And as an added bonus, if you change some of the args, you can use this second function to put the array of args back into the URL string:
|
|||||
|
The following function returns an object version of your queryString.
You can simply write
And to use this function you can write
|
||||
|
Not to beat a dead horse, but if you have underscore or lodash, a quick and dirty way to get this done is:
|
|||||
|
This code will create a object which have two method
|
||||
|
This function converts the querystring to a JSON-like object, it also handles value-less and multi-value parameters:
We perform a check for Usage:
|
||||
|
There is a nice little
Check out more examples and download here: https://github.com/websanova/js-url#url |
||||
|
This the most simple and small function JavaScript to get int ans String parameter value from URL
Source And DEMO : http://bloggerplugnplay.blogspot.in/2012/08/how-to-get-url-parameter-in-javascript.html |
|||||||||
|
I believe this to be an accurate and concise way to achieve this (modified from http://css-tricks.com/snippets/javascript/get-url-variables/):
|
||||
|
If you want array-style parameters URL.js supports arbitrarily nested array-style parameters as well as string indexes (maps). It also handles url-decoding.
|
||||
|
There's a robust implementation in Node.js's source Also TJ's qs does nested params parsing |
||||
|
Most pretty but basic:
It doesn't handle values lists such as |
||||
|
I did small URL library for my needs here: https://github.com/Mikhus/jsurl It's more common way of manipulating the URLs in JavaScript, meanwhile it's really lightweight (minified and gzipped < 1KB) and has very simple and clean API. And it does not need any other library to work. Regarding the initial question, it's very simply to do:
|
||||
|
|
||||
|
I used this code (JavaScript) to get the what is passed through the URL:
Then to assign the value to a variable, you only have to specify which parameter you want to get, ie if the URL is You can do this to get the values:
then the values would be:
Thanks, Josh |
||||
|
There are many solutions to retrieve URI query values, I prefer this one because it's short and works great:
|
||||
|
Please check and let me know your comments. Also Refer: How to get querystring value using jQuery |
|||||
|
I took this answer and added support for optionally passing the URL in as a parameter; falls back to window.location.search. Obviously this is useful for getting the query string parameters from URLs that are not the current page:
|
||||
|
If you do not wish to use a Javascript library you can use the Javascript string functions to parse window.location. Keep this code in an external .js file and you can use it over and over again in different projects.
|
||||
|
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?