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? |
|||||||||||||||||
|
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
|
||||
|
The problem with top answer on that question is that it's not support params placed after #, but sometimes it's needed to get this value also. I modify the unswer to let it parse full query string with hash sign also
|
|||||||||
|
This one works fine
taken from here |
|||||
|
A very lightweight jquery method:
And to alert ,for example ?q
|
|||||
|
I would rather use split() instead of Regex for this operation:
|
||||
|
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
|
||||
|
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.
|
||||
|
Not to beat a dead horse, but if you have underscore or lodash, a quick and dirty way to get this done is:
|
|||||
|
For those who wants a short method (with limitations):
|
||||
|
Here's an extended version of Andy E's linked "Handle array-style query strings"-version. Fixed a bug ( It will handle the following querystring...
...making it into an object that looks like...
As you can see above, this version handles some measure of "malformed" arrays, i.e. -
It seems the jury is somewhat out on repeated keys as there is no spec. In this case, multiple keys are stored as an (fake)array. But do note that I do not process values based on commas into arrays. The code:
|
||||
|
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:
|
||||
|
There's a robust implementation in Node.js's source Also TJ's qs does nested params parsing |
||||
|
|
||||
|
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. |
||||
|
Most pretty but basic:
It doesn't handle values lists such as |
||||
|
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:
|
||||
|
You already got alot of options but I guess if you're going to use node.js then you can simply do this:
|
|||||
|
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.
|
||||
|
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:
|
||||
|
quick, easy, and fast: The Function:
Usage:
|
||||
|
Here is String prototype implementation:
Example call:
|
||||
|
Thank you for your interest in this question.
Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?