I'm looking for a jQuery plugin that can get URL parameters, and support this search string without outputting the JavaScript error: "malformed URI sequence". If there isn't a jQuery plugin that supports this, I need to know how to modify it to support this.
?search=%E6%F8%E5
The value of the URL parameter, when decoded, should be:
æøå
(the characters are Norwegian).
I don't have access to the server, so I can't modify anything on it.
getURLParameter(id)
orgetURLParameter(Id)
Works the same : )Below is what I have created from the comments here, as well as fixing bugs not mentioned (such as actually returning null, and not 'null'):
Need to add the i parameter to make it case insensitive:
jQuery code snippet to get the dynamic variables stored in the url as parameters and store them as JavaScript variables ready for use with your scripts:
This may help.
What you really want is the jQuery URL Parser plugin. With this plugin, getting the value of a specific URL parameter (for the current URL) looks like this:
If you want an object with parameter names as keys and parameter values as values, you'd just call
param()
without an argument, like this:This library also works with other urls, not just the current one:
Since this is an entire URL parsing library, you can also get other information from the URL, like the port specified, or the path, protocol etc:
It has other features as well, check out its homepage for more docs and examples.
Instead of writing your own URI parser for this specific purpose that kinda works in most cases, use an actual URI parser. Depending on the answer, code from other answers can return
'null'
instead ofnull
, doesn't work with empty parameters (?foo=&bar=x
), can't parse and return all parameters at once, repeats the work if you repeatedly query the URL for parameters etc.Use an actual URI parser, don't invent your own.
For those averse to jQuery, there's a version of the plugin that's pure JS.