在 Internet Explorer 的表单提交中设置字符编码 [英] Setting the character encoding in form submit for Internet Explorer

查看:39
本文介绍了在 Internet Explorer 的表单提交中设置字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含表单的页面.此页面的内容类型为 text/html;charset=utf-8.我需要使用 ISO-8859-1 字符编码将此表单提交给服务器.这可以通过 Internet Explorer 实现吗?

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?

为表单元素设置 accept-charset 属性,像这样,适用于 Firefox、Opera 等,但不适用于 IE.

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>

此表单由服务器 A 创建,并将提交给服务器 B.我无法控制服务器 B.

This form is created by server A and will be submitted to server B. I have no control over server B.

如果我将服务器 A 设置为使用字符集 ISO-8859-1 提供内容,则一切正常,但我正在寻找一种方法,无需更改服务器 A 的编码即可使其正常工作.我还有一个问题 关于在服务器 A 中设置编码.

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:

在表单中插入一个隐藏的输入字段,其中包含一个实体,该实体仅出现在您发布(或执行 GET)的服务器接受的字符集中.

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.

示例:如果表单位于提供 ISO-8859-1 服务的服务器上,并且该表单将发布到需要 UTF-8 的服务器,请在表单中插入如下内容:

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="&#9760;" />

IE 将检测"表单包含 UTF-8 字符并在您 POST 或 GET 时使用 UTF-8.奇怪,但确实有效.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆