Ampersands in hyperlinks cause W3C validation to fail

耗尽温柔 提交于 2019-12-20 02:30:37

问题


I have a reacurring problem. I code nice standards compliant code only to have it fail due to ampersands within some of the hyperlink urls.

Does anyone know of a work around or hack for this.

Thanks


回答1:


You should URL Encode the hyperlinks, so all characters are turned into a valid ASCII format and don't contain any (X)HTML entities.

For C# use HttpUtility.UrlEncode, for PHP urlencode, for JavaScript encodeURI, etc... Finding the right method for the language you're using shouldn't be that hard.




回答2:


I code nice standards compliant code only to have it fail due to ampersands within some of the hyperlink urls.

Unescaped ampersands in URLs (or anywhere else, if they're not part of an HTML entity!) aren't "nice standards compliant code".

Turn them into & and you can accurately claim to have done this.




回答3:


Did you make them & in the links like this?

&



回答4:


CDATA works wonders where you have & in javascript strings..



来源:https://stackoverflow.com/questions/2480869/ampersands-in-hyperlinks-cause-w3c-validation-to-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!