Use Form's "Accept-charset" to submit forms between pages of different codes

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.