3

I am adding some Javascript generated by Google's Adsense on my page, but there is somethong which does not make sense to me:

<script type="text/javascript"><!--
    google_ad_client = "ca-pub-1234324234324324";
    /* LeftTop */
    google_ad_slot = "2343454355";
    google_ad_width = 200;
    google_ad_height = 200;
    //-->
</script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Why does Google add !-- at the beginning of the first script and //-- at the end? What is the purpose of this code? What does it do? Is it really necessary?

1

2 Answers 2

4

I saw this from here:

Why do we place JavaScript code inside comment fields ? It's for ensuring that the Script is not displayed by old browsers that do not support JavaScript. This is optional, but considered good practice.

2

It's supposed to make browsers that don't support Javascript ignore everything inside the <script> block by making it look like a HTML comment. It's rarely used nowadays.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.