Inconsistent parameter charset coding in web page submissions

Stefan Lennerbrant
Stefan Lennerbrant used Ask the Experts™
on
Does anybody recognize this behaviour?

With the following HTML, I open a new page (the same one) supplying a non-ascii form field parameter with value "Ϩ" (a backword "S", like)
The page itself is marked as "charset=iso-8859-1" so I expect that charset to be used for the request.

With "Form1" the request to the web server contains exactly "Ϩ" (however CGI-quoted: "Field1=%26%231000%3B")
With "Form2" the  request however contains the parameter in UTF-8 format (CGI-quoted: "Field2=%CF%A8")
What would be the cause of this difference?

Do note that in IE11 this behaviour is consistent , but in Chrome (ver 73)  I get the Form2 UTF-8 coding only when the Form2 window does not exist to begin with.
Keeping the opened Form2 window on screen, and then re-submitting from the main page (re-using the already opened Form2 window), then Chrome uses "Ϩ" coding also for Form2.

If I change the meta charset tags to "utf-8", then I (of course) always get UTF-8 coding for both Form1 and Form2.

So... why is UTF-8 used in the request for Form2, even though I state "iso-8859-1" as charset (my http server never specifies a charset in the http headers, so the "meta charset" info is the only one available)
Any ideas?

The file is to be named "test.htm"
<html>
<head>
<meta http-equiv="Content-Type" content="iso-8859-1">
<meta charset="iso-8859-1">
<script>
function submit1()
{
  document.Form1.submit();
}
function submit2()
{
  var win = window.open('', 'submit2win');
  if(!win) {
    alert('Cannot open window');
    return;
  }
  var doc = win.document.open('about://', 'replace');
  if(!doc) {
    alert('Cannot open document');
    return;
  }
  doc.writeln('<'+'html>');                                                                                   
  doc.writeln('<'+'head>');
  doc.writeln('<meta http-equiv="Content-Type" content="iso-8859-1">');
  doc.writeln('<meta charset="iso-8859-1">');
  doc.writeln('<\/head>');
  doc.writeln('<'+'body>');
  doc.writeln('<'+'form name=Form2 action="test.htm">');
  doc.writeln('<input name=Field2 type=hidden value="&#1000;">');
  doc.writeln('<\/form>');
  doc.writeln('<'+'script>document.Form2.submit();<\/script>');
  doc.writeln('</body>');
  doc.writeln('</html>');
  doc.close();
}
</script>
</head>
<body>
The time is:
<script>
  var now = new Date();
  document.writeln(now.getTime());
</script>
<br><br>
<form name=Form1 action="test.htm">
<a href="javascript:submit1();">Submit Form1 in this window with Field1="&#1000;"</a>
<input name=Field1 type=hidden value="&#1000;">
</form>
<a href="javascript:submit2();">Submit Form2 in new window with Field2="&#1000;"</a>
</form>
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Here you may see it in action, by the way:

  http://tolva.se/test/test.htm

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial