开发者

Remove trailing ]> from the page

I'm using a doctype with custom attributes to validate XHTML. Here is my Doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
[
<!ATTLIST div开发者_运维技巧 data-localized CDATA #IMPLIED> 
]>

But the problem is that it's displaying "]>" when I load my page on the browser. The XHTML validates fine.


Workaround would be to remove it using javascript. Add the script after your body declaration e.g.

<html>
<body>
<script type="text/javascript">

 function removeFirstTwo() {
  try {
     var htmlBody = document.getElementsByTagName("BODY")[0];
     if (htmlBody.firstChild.nodeValue.substr(0,2) == "]>") {
       htmlBody.firstChild.nodeValue = "";
     }
   } catch(e) { 
     //do nothing 
   }
 }

 removeFirstTwo();

</script>
...


Check out the article in A list apart -

Unfortunately, when you display the file in a browser, the ]> shows up on the screen.

It points out a solution that involves using a separate DTD file (which will fail in W3C validator...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜