Specify the form submission encoding method under IE to add to favorites
When sending data across services, websites, or business upgrades, we sometimes need to specify the encoding method for sending data. For example, the page is UTF-8 encoded, the sent data is encoded in gb2312 format. When doing Ajax development, we often use VBscript or use dictionary to solve this problem (http://www.blogjava.net/emu/articles/31756.html ). However, some services may not need to be as complicated as Ajax, and it is more natural to submit them using forms.
In fact, the form tag in HTML has an Accept-charset attribute, which can help us solve this problem. Unfortunately, the silly IE browser does not sell its account even though it recognizes accept-charset. What encoding is used when the IE form is submitted depends entirely on the charset of the page. Fortunately, ie in charset this problem on the silly end (see http://www.blogjava.net/emu/archive/2007/08/21/138247.html), fooling it, it will be obedient:
View plaincopy to clipboardprint?
<HTML> <br/> <pead> <br/> <meta http-equiv = Content-Type content = "text/html; charset = UTF-8 "> <br/> <script language =" JavaScript "> <br/> var isie = !! Window. activexobject; <br/> If (isie & document. charset! = "UTF-8") location. reload (false ); <br/> </SCRIPT> <br/> <title> encode before form post </title> <br/> <meta name = "author" content = "emu"> <br/> </pead> <br/> <body> <br/> <form action = "#" Accept-charset = "gb2312" onsubmit = "If (isie) document. charset = 'gb2312' "> <br/> <input name =" test "value =" "readonly> <br/> <input type = submit> <br/> </form> <br/> </body> <br/> </ptml> <br/>
To put it simply, tell IE that the current page is gb2312 encoded before the form is sent:
<Form accept-charset = "gb2312" onsubmit = "If (isie) document. charset = ''gb2312''">
Accept-charset = "gb2312" is written to other browsers that are not so stupid.
In order to show that it is really silly, ie is not only setting document. charset does not use the new encoding to interpret the page, but also tries to use the new encoding to interpret the page while moving forward and backward (I specially use # As the action. But fortunately, you can use the script to judge it, and you can use the script to refresh the page to solve this problem:
If (isie & document. charset! = "UTF-8") location. Reload (false );
Example: Submit to Baidu
View plaincopy to clipboardprint?
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <meta name = "publisher" content = "tidecms"> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8 "/> <br/> <title> form submission </title> <br/> <body> <br/> <form action =" http://www.baidu.com/s "Name = "F" Accept-charset = "GBK" onsubmit = "document. charset = 'gbk' "target =" _ blank "> <input type =" text "maxlength =" 100 "size =" 42 "id =" kW "name =" WD" autoComplete = "off"/> <input type = "Submit" id = "SB" value = ""/> <span id = "HP"> <a href =" /gaoji/preferences.html "mce_href =" gaoji/preferences.html "> Settings </a> <br/> <a href ="/gaoji/advanced.html "mce_href =" gaoji/advanced.html "> advanced </a> </span> </form> <br/> </body> <br/> </ptml> <br/>
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/chabb/archive/2010/05/10/5573409.aspx