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.
If you don't know what the URL parameters will be and want to get an object with the keys and values that are in the parameters, you can use this:
Calling getParameters() with a url like
/posts?date=9/10/11&author=nilbus
would return:I won't include the code here since it's even farther away from the question, but weareon.net posted a library that allows manipulation of the parameters in the URL too:
After reading all of the answers I ended up with this version with + a second function to use parameters as flags
You can use the browser native location.search property:
But there are some jQuery plugins that can help you:
You should not use jQuery for something like this!
The modern way is to use small reusable modules through a package-manager like Bower.
I've created a tiny module that can parse the query string into an object. Use it like this:
I created a simple function to get URL parameter in JavaScript from a URL like this:
OUTPUT:
18
Based on the 999's answer:
Changes:
decodeURI()
is replaced withdecodeURIComponent()
[?|&]
is added at the beginning of the regexp