html表单的编码及ie下面的hack
2014-03-18 14:10
417 查看
问题是这样的,我的代码是utf8编码的,但是和我的程序接口的程序必须接收gb2312的编码格式,由于我这边不方便使用ajax的方式,因此我在form里加了charset,在FF等浏览器都没问题,但是IE却一直没有效果。
代码如下:
评论 (1) • 分享 • 链接 • 2012-08-20
0
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
在提交页面中字符编码最好与后台处理编码一致。 – tonyzhang 2012-08-23
做了下测试,下面的方法应该可以,供参考:
可以加入一个隐藏的input,例如:
推荐看一下这里,希望对你有帮助。
评论 (1) • 链接 •
2012-08-20
代码如下:
<form action="#" accept-charset="GB2312" > <input name="test" value="测试" readonly> <input type=submit> </form>
评论 (1) • 分享 • 链接 • 2012-08-20
0
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
在提交页面中字符编码最好与后台处理编码一致。 – tonyzhang 2012-08-23
做了下测试,下面的方法应该可以,供参考:
<HTML> <HEAD> <meta http-equiv=content-type content="text/html; charset=UTF-8"> <SCRIPT LANGUAGE="JavaScript"> var isIE=!!window.ActiveXObject; if(isIE && document.charset!="utf-8")location.reload(false); if(location.search) alert("编码为:"+location.search.substr(6)) </SCRIPT> <TITLE>encode before form post</TITLE> <META NAME="Author" CONTENT="emu"> </HEAD> <BODY> <form action="#" accept-charset="GB2312" onsubmit="if(isIE)document.charset='GB2312'"> <input name="test" value="测试" readonly> <input type=submit> </form> </BODY> </HTML>
可以加入一个隐藏的input,例如:
<input name="iehack" type="hidden" value="☠" />
推荐看一下这里,希望对你有帮助。
评论 (1) • 链接 •
2012-08-20
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 are 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 UFT-8 when you POST or GET. Strange, but it does work.
| |||||||||||||||||
|
ith decent browsers:<form accept-charset="ISO-8859-1" .... > With IE (any): document.charset = 'ISO-8859-1'; // do this before submitting your non-utf8 <form>!
| |||||
|
相关文章推荐
- 在IE下面指定表单编码方式
- 在IE下面指定表单编码方式
- 本地存储在IE下面的编码问题及解决方法
- 本地存储在IE下面的编码问题及解决方法
- 在IE下面指定表单编码方式
- 在IE下面指定表单提交编码方式
- IE各浏览器hack
- ie6.7.8的hack
- 解决extjs4.1在IE和FF下面字体太上问题,以及按钮的字体是斜体的问题,在extj-all.css后加
- utf-8编码下空格 在火狐和ie里不一致(火狐 网页 utf-8 空格)
- linux下面如何将文件编码批量转化
- javascript里面的document.head在IE下面不兼容问题
- linux下面 c++ string的编码
- CSS半透明滤镜在FIREFOX和IE下面的能够通用的写法
- 16、2005年11月金山笔试题。编码完成下面的处理函数。函数将字符串中的字符'*'移到串的前部分,前面的非'*'字符后移,但不能改变非'*'字符的先后顺序,函数返回串中字符'*'的数量。如原始串为:
- IE css hack汇总
- IE&Firefox Hack
- 88.2005 年 11 月金山笔试题。编码完成下面的处理函数。
- getElementsByName 在IE下面的bug 的解决
- IE 6.0下面 png格式的图片不透明的解决方法