0

我正在尝试编写一个仅 MSIE 的 HTML 页面(我将其称为“标题页面”),它允许某人通过单击按钮来保存生成的 HTML 网页(我将其称为“新页面”)。

我发现出现的“另存为”对话框不允许将“新页面”保存为没有 BOM 的 UTF-8。相反,它被保存为 Unicode(UTF-8),而浏览器又将其确定为 UTF-16。以下是“标题页”的示例代码:

<html>
<head>
<script>

/** 
  *Takes the information in the form and arranges it in the proper format.
*/
function save()
{
str = "Hello World";            

mydoc = document.open();

mydoc.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");       
mydoc.write("\r\n\r\n");
mydoc.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n\t<head>\r\n\r\n\r\n\r\n\r\n<!--LOOK FOR \"EDIT HERE\"//-->\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\r\n\r\n<title>");

    /*Inserts str in the title*/
    mydoc.write(str);

    mydoc.write("</title>\r\n\r\n\t</head>\r\n\r\n\r\n\t<body>\r\n\r\n\r\n<!--EDIT HERE//-->\r\n\r\n<H1>");
    /*Inserts form variables from here*/
    mydoc.write(str);
    mydoc.write("</H1>\r\n\r\n\r\n<!--DO NOT EDIT BEYOND THIS POINT//-->\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n</body>\r\n</html>\r\n\r\n");

mydoc.execCommand("saveAs",true,"*.html");
mydoc.close();
}

</script>
</head>


<body>
<p align=right><input type="button" value="save" onclick="save()"></p>
</body>
</html>

我用http://web-sniffer.net/检查了“新文件”,它告诉我“新文件”是以这种方式保存的:

<code>ÿþ!<�D�O�C�T�Y�P�E� �h�t�m�l� �P�U�B�L�I�C� �"�-�/�/�W�3�C�/�/�D�T�D� �X�H�T�M�L� �1�.�0 �T�r�a�n�s�i�t�i�o�n�a�l�/�/�E�N�"� �"�h�t�t�p�:�/�/�w�w�w�.�w�3�.�o�r�g�/�T…&lt;/code>

我能做些什么来阻止它把“新页面”保存为 UTF-16 吗?还是与代码无关?

此外,“另存为”对话框中有一个下拉菜单,据说可以让我更改字符编码,但真正做的只是保存“标题页面”而不是“新页面”。

4

1 回答 1

1

尝试将页面保存在其他编辑器中,例如 Notepad++,其中设置特定编码更清晰:

http://download.cnet.com/Notepad/3000-2352_4-10327521.html

于 2011-03-31T16:14:48.193 回答