为什么Google不支持带有& amp;的有效网址?在查询字符串? [英] Why does Google not support valid URLs with & in query string?

查看:108
本文介绍了为什么Google不支持带有& amp;的有效网址?在查询字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用W3C验证器验证以下HTML会引发3个错误(截至2013-10-30):

Trying to validate the following HTML with the W3C validator will throw 3 errors (as of 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将会导致无法渲染静态地图图像.尝试使用以下URL嵌入img标记作为其src属性的值:

Unfortunately, conforming to the W3C here will lead to the static maps image not being rendered. Try to embed an img tag with the following URL as the value for its src attribute:

<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&amp;size=279x183&amp;markers=50.916780,5.347420&amp;sensor=false">

这会返回一个错误,表明Google:

This returns an error by Google stating:

Google Maps API服务器拒绝了您的请求.无效的请求.缺少尺寸"参数.

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.

为什么Google Static Maps API不支持查询字符串中带有&amp;的有效URL?

Why does the Google Static Maps API not support valid URLs with &amp; in query string?

推荐答案

您正确地逃避了&字符.

You escaped the & characters correctly.

请注意,您不能将带有转义符的URI直接输入到浏览器的地址栏中.只有在HTML中使用时(即在hrefsrc属性中),它才有效.

Note that you can’t enter the URI with escaped ampersands directly into the address bar of your browser. It only works if used in HTML (i.e. in href and src attributes).

有问题的URL可以完美地用作链接(也可以作为图片).

请注意,您可能不要没有逃脱这些&"号(看起来似乎是明确的);但是为了安全起见,只需将它们全部逃脱即可.

Note that you probably don’t have to escape these ampersands (as they seem to be unambiguous); but to be always on the safe side, simply escape them all.

这篇关于为什么Google不支持带有&amp; amp;的有效网址?在查询字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆