html - 为什么 Twitter 和 Google API 文档不对 URL 中的 & 符号进行编码?

标签 html url cross-browser html-entities

have read我应该将我的符号编码为 HTML 中的 &
然而,来自受人尊敬的公司的大量代码样本不知何故忘记这样做

只是我头脑中的几个例子:

Google Web Fonts示例代码:

<link href='http://fonts.googleapis.com/css?family=PT+Sans&subset=latin,cyrillic' rel='stylesheet' type='text/css'>

Google Maps文档:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&language=ja">

Twitter Anywhere官方教程:

<script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script>

在链接中转义&符号有什么真正的好处吗?
这与浏览器怪癖有关吗?这只是文档中的错误吗?

Dear answerers, please make sure you're answering the right question.

I know I should escape ampersands per spec. I also know why the mechanism was invented in the first place. I'm not asking about this. My question is:

Is there a reason API documentation by respectable companies often violates this rule?

最佳答案

这里有两个不同的上下文。

  1. 在 javascript href 的上下文中,& 很好,不应该被编码。
  2. 在 HTML 链接中 & 是被禁止的并且应该被转义。

在 HTML 链接上下文中,在将地址传递给 HTTP 进程之前,将对 HTML 字符实体进行解码; URL 编码的字符不会,因为服务器可以直接读取它。

关于html - 为什么 Twitter 和 Google API 文档不对 URL 中的 & 符号进行编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8874706/

相关文章:

cross-browser - 有没有离线的跨浏览器测试工具

javascript - 当元素溢出时如何增加元素的高度

html - 如何减少 CSS 网格元素之间的空间

javascript - 将 ng-model 值设置为 div 文本

css - Jquery-mobile css 打扰了我为按钮定制的 css

php - 使用 .htaccess 强制将 xxx.php URL 转发到 xxx

ios - 电子邮件中的条件深层链接或 url

url - 描述性 URL 与基本 URL

html - 我怎样才能让两个元素彼此相邻?

jquery - SCRIPT5 : Access is denied. 在 IE 上使用 parse.js 时