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*

Currently rated 4.9 by 16 people

  • Currently 4.9375/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

HTML | Humour

Comments

12/4/2007 11:23:55 PM

Sam

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

Colin Cochrane

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

Colin Cochrane ca

12/18/2007 12:58:52 PM

Gary

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 us

12/18/2007 1:17:43 PM

Colin Cochrane

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 ca

12/18/2007 1:56:29 PM

Gary

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

Gary us

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/6/2008 4:07:27 AM

Powered by BlogEngine.NET 1.3.1.0

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

Recent posts

Disclaimer

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

Sign in