URL中的Unicode字符(一切正常 - IE除外) [英] Unicode characters in a URL (all ok - except for IE)
问题描述
我有一些简单的HTML链接到另一个HTML文件 - 但该文件名包含一个Unicode字符。根据我对链接的编码方式,Windows上的IE浏览器不会打开它 - 而且所有其他浏览器(Windows和Mac)都可以使用相同的链接。任何指针都是非常受欢迎的。
这里似乎很关键的是,我打开本地磁盘上的HTML(即,它不是由Web服务器提供的)。
< html>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< title>网站< / title>
< / head>
< body>
< a href =%C3%A9.html>在IE上失败 - 可在其他地方使用(Firefox,Chrome,Safari)< / a>
< p />
< a href =é.html>适用于IE< / a>
< / html>
谢谢
Craig
这在以下讨论 IEBlog 关于MSDN的文章:
非US-ASCII字符
US-ASCII之外的字符可能出现在Windows文件路径中,因此它们允许在文件IRI中使用。 (URI仅被定义为US-ASCII,因此当在字符串中包含非US-ASCII字符时,实际创建的内容称为IRI:国际化资源标识符。)不要使用百分比编码的八位字节表示非US-ASCII字符,因为在文件URI中,百分比编码的八位字节被解释为用户当前代码页中的一个字节。包含US-ASCII外部字节的百分比编码字节的URI的含义将根据查看文档的区域设置进行更改。相反,表示非US-ASCII字符时,应该直接在编写IRI文档的编码中使用该字符。例如:
不正确:file:/// C:/example%E3%84%93.txt
正确:file:/// C:/ exampleㄓ.txt
换句话说,由于您的HTML使用的是UTF-8,因此URL必须使用非$百分比编码的UTF-8字节作为 这是互联网Explorer设计用于工作。这不是一个错误。其他浏览器只是做一些不同的事情,就是这样。除非您可以将Web服务器配置为向其他浏览器提供不同的HTML到IE,否则您将不得不使用客户端技术,例如条件注释,例如: I have some simple HTML which has a link to another HTML file - but that file name contains a unicode character. Depending upon how I encode the link, IE on Windows will not open it - and yet the very same link works on all the other browsers (Windows and Mac) Any pointers would be most welcome. What seems to be key here is that I'm opening the HTML on a local disk (i.e. it's not being served up by a web server.) Thanks Craig This is discussed in the following IEBlog article on MSDN: Non US-ASCII Characters Characters outside of US-ASCII may appear in Windows file paths and accordingly they’re allowed in file IRIs. (URIs are defined as US-ASCII only and so when including non-US-ASCII characters in a string, what you've actually created is called an IRI: Internationalized Resource Identifier.) Don’t use percent-encoded octets to represent non US-ASCII characters because, in file URIs, percent-encoded octets are interpreted as a byte in the user’s current codepage. The meaning of a URI containing percent-encoded octets for bytes outside of US-ASCII will change depending on the locale in which the document is viewed. Instead, to represent a non-US-ASCII character you should use that character directly in the encoding of the document in which you are writing the IRI. For instance: Incorrect: file:///C:/example%E3%84%93.txt In other words, since your HTML is using UTF-8, the URL must use non-percent-encoded UTF-8 octets for the This is how Internet Explorer is designed to work. It is not a bug. The other browsers are simply doing something different, that's all. Unless you can configure the webserver to deliver different HTML to IE vs other browsers, you will have to use client-side technology instead, such as conditional comments, eg: The 这篇关于URL中的Unicode字符(一切正常 - IE除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!é
字符,这就是为什么é.html
有效,Ã。.html
的文件。
< HTML>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
< meta http-equiv =X-UA-Compatiblecontent =IE = EmulateIE9>
< title>网站< / title>
< / head>
< body>
<! - [if IE]>
< a href =é.html>适用于IE< / a>
<![endif] - >
<! - [if!IE]> - >
< a href =%C3%A9.html>在其他地方运作< / a>
<! - <![endif] - >
< / html>
X-UA兼容
元标记是因为Microsoft 删除了对IE 10中HTML条件注释的支持当它实现对HTML5的支持时。<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>website</title>
</head>
<body>
<a href="%C3%A9.html">Fails on IE - works everywhere else (Firefox, Chrome, Safari)</a>
<p />
<a href="é.html">Works on IE</a>
</html>
Correct: file:///C:/exampleㄓ.txté
character, which is why é.html
works and %C3%A9.html
fails - there is no file named é.html
, for example.<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9">
<title>website</title>
</head>
<body>
<!--[if IE]>
<a href="é.html">Works on IE</a>
<![endif]-->
<!--[if !IE]> -->
<a href="%C3%A9.html">Works everywhere else</a>
<!-- <![endif]-->
</html>
X-UA-Compatible
meta tag is needed because Microsoft removed support for HTML conditional comments in IE 10 when it implemented support for HTML5.