html – URL中的Unicode字符(一切正常 – IE除外)

前端之家收集整理的这篇文章主要介绍了html – URL中的Unicode字符(一切正常 – IE除外)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些简单的 HTML,它有一个指向另一个 HTML文件链接 – 但该文件名包含一个unicode字符.根据我对链接进行编码的方式,Windows上的IE将无法打开它 – 但是所有其他浏览器(Windows和Mac)上的链接都是相同的.任何指针都是最受欢迎的.

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

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

谢谢

克雷格

解决方法

这在MSDN上的以下 IEBlog文章中讨论:

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工作和é.html失败的原因 – 没有名为Ã的文件例如,©.html.

这就是Internet Explorer的工作方式.这不是一个bug.其他浏览器只是做了不同的事情,就是这样.除非您可以将Web服务器配置为向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兼容元标记,因为Microsoft removed support for HTML conditional comments in IE 10实现了对HTML5的支持.

原文链接:https://www.f2er.com/html/228052.html

猜你在找的HTML相关文章