I was just wondering, what is the difference between
<script>
and
<script type = 'text/javascript'>
Is it different for different webservers?
For example,(I know it's incorrect to provide a link from w3schools, but look)
http://www.w3schools.com/js/tryit.asp?filename=tryjs_myfirst
Using chrome, I visited w3schools and I realised that the <script>
tag is all I need.
However, when I did an offline javascript test, i realised that i need the
<script type = 'text/javascript'>
tag. Why is this so?
text/javascript is the default type, so you can omit it, it makes no difference. Nothing, except in very special cases with old IE where if the first script element set the type to some other scripting language (e.g. VBScript) then that was the default if no type was specified.
The <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.
The language attribute was used when <script> was introduced in HTML 3.2 and took a language name (such as JavaScript ). The type attribute replaced it in HTML 4.0 (as everything describing non-HTML media started taking MIME types) and takes a MIME type (such as text/javascript ).
async: It is used to specify the script is executed asynchronously. charset: It is used to specify the character encoding used in an external script file. defer: It is used to specify that the script is executed when the page has finished parsing. src: It is used to specify the URL of an external script file.
In HTML 4, the type attribute is required. In my experience, all browsers will default to text/javascript if it is absent, but that behaviour is not defined anywhere. While you can in theory leave it out and assume it will be interpreted as JavaScript, it's invalid HTML, so why not add it.
In HTML 5, the type attribute is optional and defaults to text/javascript
Use <script type="text/javascript">
or simply <script>
(if omitted, the type is the same). Do not use <script language="JavaScript">
; the language attribute is deprecated
Ref :
http://social.msdn.microsoft.com/Forums/vstudio/en-US/65aaf5f3-09db-4f7e-a32d-d53e9720ad4c/script-languagejavascript-or-script-typetextjavascript-?forum=netfxjscript
and
Difference between <script> tag with type and <script> without type?
Do you need type attribute at all?
I am using HTML5- No
I am not using HTML5 - Yes
<script>
is HTML 5.
<script type='text/javascript'>
is HTML 4.x (and XHTML 1.x).
<script language="javascript">
is HTML 3.2.
Is it different for different webservers?
No.
when I did an offline javascript test, i realised that i need the
<script type = 'text/javascript'>
tag.
That isn't the case. Something else must have been wrong with your test case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With