尝试使用 W3C 验证器验证以下 HTML 将抛出 3 个错误(截至 2013 年 10 月 30 日):
<!DOCTYPE html>
<head><title>asdf</title></head>
<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=279x183&markers=50.916780,5.347420&sensor=false" alt="map">
这 3 个错误都是相同的:
& did not start a character reference. (& probably should have been escaped as &.)
不幸的是,这里遵守 W3C 将导致静态 map 图像无法渲染。尝试嵌入 img
标记,并将以下 URL 作为其 src
属性的值:
<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=279x183&markers=50.916780,5.347420&sensor=false">
这会返回 Google 的错误,指出:
The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.
为什么 Google Static Maps API 不支持查询字符串中包含 &
的有效网址?
最佳答案
您正确转义了 &
字符。
请注意,您无法将带有转义与号的 URI 直接输入到浏览器的地址栏中。它仅在 HTML 中使用时才有效(即在 href
和 src
属性中)。
URL in question works完美地作为链接(也作为图像)。
请注意,您可能don’t have to escape这些&符号(因为它们看起来很明确);但为了安全起见,只需避开它们即可。
关于url - 为什么 Google 不支持查询字符串中包含 & 的有效网址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19678879/