Home Blog Wiki
Twitter Subscribe to PHP Blog RSS Feed Email RSS
Home > 未分类 > 遵循W3C修改引用的HTML代码实例

遵循W3C修改引用的HTML代码实例

添加评论 五月 9th, 2009
可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明

多数的网站或者博客中,都会引用一些其他网站提供的代码,以实现一些功能或者动态的广告条目,但直接复制用来的话,会发现部分代码就会导致很多的HTML校验错误,因此有必要注意一下代码的规范性。

1.Twitter网站生成的侧边栏代码里包含如下不符合标准:


<ul id="twitter_update_list"></ul>

话说如“ <head>”之类的元素必须包含一个“<title>”子元素,名单的 (ul, ol, dl)等必须包含一个子项(li,or dt, dd)等等,于是这样处理通过校验:


<ul id="twitter_update_list"><li></li></ul>

不过添加的标签可能会使放置位置的某些样式发生变化,需要按实际情况处理。

2.Yupoo网站自动生成的侧边栏代码包含如下不符合标准:


<script type="text/javascript" language="javascript" src="http://www.yupoo.com/photos/gen_badge?userid=ff80808119321c500119335a860224f4&amp;type=1&amp;source=user&amp;mysource=mytags&amp;tags=sidebar&amp;count=6&amp;line=2&amp;size=s&amp;icon=hide&amp;direction=horizontal&amp;boxSize=400">
</script>

校验时提示:

…cannot generate system identifier for general entity “source”

An entity reference was found in the document, but there is no reference by that name defined. Often this is caused by misspelling the reference name, unencoded ampersands, or by leaving off the trailing semicolon (;). The most common cause of this error is unencoded ampersands in URLs as described by the WDG in “Ampersands in URLs”.

Entity references start with an ampersand (&) and end with a semicolon (;). If you want to use a literal ampersand in your document you must encode it as “&amp;” (even inside URLs!).

一些链接脚本内的&符号不符合标准,必须全部替换为&amp;,这是很多外链脚本与广告脚本里常常出现的问题,必须想办法将原文件替换。

… to be continued.

Your opinion counts (您的意见很重要)