gpt4 book ai didi

html - URL 中的 Unicode 字符(都可以 - 除了 IE)

转载 作者:行者123 更新时间:2023-11-28 07:46:13 25 4
gpt4 key购买 nike

我有一些简单的 HTML,其中包含另一个 HTML 文件的链接 - 但该文件名包含 unicode 字符。根据我对链接进行编码的方式,Windows 上的 IE 不会打开它 - 但相同的链接可以在所有其他浏览器(Windows 和 Mac)上运行。任何指针都将受到欢迎。

这里的关键似乎是我在本地磁盘上打开 HTML(即它不是由网络服务器提供的。)

<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>

谢谢

克雷格

最佳答案

这将在下面讨论 IEBlog MSDN 上的文章:

File URIs in Windows

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
Correct: file:///C:/exampleㄓ.txt

换句话说,由于您的 HTML 使用 UTF-8,因此 URL 必须使用非百分比编码的 UTF-8 八位字节作为 é 字符,这就是 é.html 的原因 有效,而 %C3%A9.html 失败 - 例如,没有名为 é.html 的文件。

这就是 Internet Explorer 的工作原理。这不是一个错误。其他浏览器只是做了一些不同的事情,仅此而已。除非您可以将网络服务器配置为向 IE 与其他浏览器提供不同的 HTML,否则您将不得不使用客户端技术,例如条件注释,例如:

<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 元标记,因为 Microsoft removed support for HTML conditional comments in IE 10当它实现对 HTML5 的支持时。

关于html - URL 中的 Unicode 字符(都可以 - 除了 IE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27407829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com