A Code Snippet That Speaks For Itself

by Colin Cochrane 12/4/2007 12:18:00 PM

While working on a client's site today I came across this gem that I thought you might enjoy.  I'll let the snippet speak for itself.


<script type="text/javascript">
document.write('<');
document.write('!-- ');
</script>
&lt;!--
<noscript>
(Removed to protect anonymity of client)
</noscript>
<!--//-->

*Smacks Forehead*

Tags: ,

HTML | Humour

Comments (5) -

12/4/2007 11:23:55 PM

That looks awful. I am not really familiar with this stuff though--did some code generator make that? If so, which one? I guess if the HTML works, it can't be that bad. A lot of pages don't even work.

Sam

12/4/2007 11:42:29 PM

I'm sad to say that it is man-made.  The site in question is all hand-coded.

Colin Cochrane Canada

12/18/2007 12:58:52 PM

OK - for those of us who are new to HTML and Javascript yet thoroughly enjoy your work here, can you spell out what's so funny about the code?

Gary United States

12/18/2007 1:17:43 PM

You've probably seen web documents where the content of a <script> element has been wrapped in an SGML comment tag like so:
<script type="text/javascript">
<!--
function dosomething(){}
-->
</script>

The purpose of the comment tag is to "hide" the script from older browsers that don't support Javascript.  Without the comment tag those browsers will render the contents
of the <script> element as normal text.  For instance, a page with the following markup...

*****************************
<body onload="dosomething()">
<h1>Products</h1>
<script>
function dosomething(){}
</script>
<p> This is my product! </p>
</body>
*****************************

...would end up displaying as...

******************************
Products
function dosomething(){}

This is my product!
******************************

With this in mind, the snippet in the original post is amusing because it's using javascript to output a comment tag to hide the script from those older browsers...that don't support Javascript.

Colin Cochrane Canada

12/18/2007 1:56:29 PM

Thanks for the insight. That is very funny. Keep up the great work!

Gary United States

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Powered by BlogEngine.NET 2.5.0.6

All Content and Intellectual Property is under Copyright Protection | Colin Cochrane ©2007

About the author

Colin Cochrane

Colin Cochrane

SEO and ASP.NET Developer.

Recent comments

Archive

Authors

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. © Copyright Colin Cochrane 2012

Sign in