Accept-charset
A rarely used form attribute can be used to implement form submission in pages with different codes. Transferred from Old Wang's Baidu space, recorded here.
Author: Lao Wang
Problem Background:
The two application codes are different. One is GBK encoding, and the other is UTF-8 encoding. Now we need to use the form in the GBK encoding application to submit data to the UTF-8 encoding application, it is clear that if you do not do special processing, there will be garbled.
Solution:
Of course, you can use the iconv or MB extension to convert the encoding, but this is not what we need.
In W3, we introduced an uncommon property: Accept-charset, which can be used to meet our needs.
Write the following code on the GBK encoding page:Code:
<Form method = "Post" Action = "..."Accept-charset = "UTF-8">
...
</Form>
Such code has no problem in normal browsers such as Firefox, but the abnormal IE browser is no longer available. We have to use a method of hack that does not stream:
<Form method = "Post" Action = "..."Accept-charset = "UTF-8" onsubmit = "document. charset = 'utf-8 ';">
...
</Form>
The rest of the work will be done by the browser.