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

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

问题描述

我有一个包含表单的页面。此页面提供内容类型为text / html; charset = utf-8。我需要使用ISO-8859-1字符编码将此表单提交给服务器。这是可能的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="&#9760;" />

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天全站免登陆