在Internet Explorer中为表单提交设置字符编码 [英] Setting the character encoding in form submit for Internet Explorer
问题描述
将accept-charset属性设置为form元素,像这样,适用于Firefox,Opera等,但不适用于IE。
< form accept-charset =ISO-8859-1>
...
< / form>
编辑:此表单由服务器A创建,并将提交给服务器B.我无法控制在服务器B上。
如果我将服务器A设置为使用字符集ISO-8859-1提供内容,一切正常,但是我正在寻找一种方法,使其无需更改服务器A的编码。我有另一个问题关于在服务器A中设置编码。
有一个简单的黑客:
在窗体中插入一个隐藏的输入字段,该实体只发生在字符中,设置您的发布(或做一个GET)接受的服务器。
示例:如果表单位于服务于ISO-8859-1的服务器上,并且该表单将发布到期望使用UTF-8的服务器,请按以下格式插入以下内容:
< input name =iehacktype =hiddenvalue =&#9760; />
IE然后将检测表单包含UTF-8字符,并使用UTF-8你POST或GET。奇怪,但它确实有效。
I have a page that contains a form. This page is served with content type text/html;charset=utf-8. I need to submit this form to server using ISO-8859-1 character encoding. Is this possible with Internet Explorer?
Setting accept-charset attribute to form element, like this, works for Firefox, Opera etc. but not for IE.
<form accept-charset="ISO-8859-1">
...
</form>
Edit: This form is created by server A and will be submitted to server B. I have no control over server B.
If I set server A to serve content with charset ISO-8859-1 everything works, but I am looking a way to make this work without changes to server A's encoding. I have another question about setting the encoding in server A.
There is a simple hack to this:
Insert a hidden input field in the form with an entity which only occur in the character set the server your posting (or doing a GET) to accepts.
Example: If the form is located on a server serving ISO-8859-1 and the form will post to a server expecting UTF-8 insert something like this in the form:
<input name="iehack" type="hidden" value="☠" />
IE will then "detect" that the form contains a UTF-8 character and use UTF-8 when you POST or GET. Strange, but it does work.
这篇关于在Internet Explorer中为表单提交设置字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!