What is the the difference in writing different Script tags like <script>....
or <script language="javascript">.....
or <script type="text/javascript">...........
?
They all do same things, what is different?
What is the the difference in writing different Script tags like <script>....
or <script language="javascript">.....
or <script type="text/javascript">...........
?
They all do same things, what is different?
<script>
can contain more than just Javascript. It can hold many type of other scripts like VbScript, classic ASP script, c#, even PHP.
<script>
means you are writing a script
<script language="......">
defines the language in which you are going to write your script
<script type=".........">
defines the content-Type of your script
According to w3c spec, type
attribute is required, and determines script language, whereas language
attribute (which does more or less the same) is deprecated in favor of type
, so you should use type
attribute.
In HTML 4.01 the type attribute is required. http://www.w3.org/TR/REC-html40/interact/scripts.html#adef-type-SCRIPT
In practice though, all commonly used browsers default this to text/javascript, so there isn't really a need to specify it unless you care about validators or older versions of IE. The HTML5 spec makes it optional. http://www.whatwg.org/specs/web-apps/current-work/#attr-script-type
<script language="javascript">
HTML 3.2 — The first attempt
<script type="text/javascript">
HTML 4.x and XHTML 1.x — using MIME types for everything. This is the current standard. Use this.
<script>
HTML 5 (draft) — "Ah, too many authors don't care, browsers error recover from it anyway, lets all but give up on the possibility other other embedded scripting languages being used"