Friday 12 January 2018

javascript - Get escaped URL parameter

itemprop="text">


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.



Answer




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 href="https://github.com/sindresorhus/query-string" rel="nofollow">module
that can parse the query string into an object. Use it like
this:



// parse the query string
into an object and get the
property

queryString.parse(unescape(location.search)).search;
//=>
æøå

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...