Hello guys i have this form:
<form action='file:///C:/Users/amministratore/Desktop/google_cse/ricerca.html' method="get" target='_blank' id='cse-search-box'>
<input type='text' name='q' size='35' />
<input type="submit" name="sa" value="Search" />
</form>
e this code js:
var linkcodificato= self.location.href;
var link= decodeURIComponent(linkcodificato);
I can decode many characters (? |! And many others) but not the accented letters ... why?
à = %E0
EDIT
In my search bar i search:
"hello à"
the url that i have is this:
?q=Hello+%E0
The problem is that %E0
represents the á
character in ANSI
(Windows-1252
) encoding, while it is invalid in utf-8
.
You can avoid this behaviour by making sure that:
Your html
file is saved in utf-8
encoding. How to do this, depends on your editor, but you should look for character encoding options in "Save As", or "Preferences".
You specify the utf-8
encoding in your html
file itself, for example by putting <meta charset="utf-8">
in the head
part.
If with the above two steps it still does not work, you can force the form
to submit the data in utf-8
encoding by adding the attribute accept-charset="UTF-8"
to the form
tag.
With this set-up you'll find that the á
character just stays as-is in the url
. However, the location.href
will still be encoded, but if you did the above, the encoding will now have %C3%A0
instead of the offending %E0
, and that will nicely convert to à
when you use decodeURIComponent
.
Whenever you make changes, make sure to refresh the original page, and to resubmit the form.
Here is a suggested start of your html
code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
With the above you ensure that your document runs in utf-8
mode.