Do you still Hide from browsers that do not support JavaScript? [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
开发者_高级运维Closed 11 years ago.
Improve this questionSome of the examples I'm reading start with:
<script language="javascript" type="text/javascript">
<!-- Hide from browsers that do not support JavaScript
// --> Finish hiding
</script>
- Do you still wrap your js code in html comments?
- Do you still include language="javascript"?
- Do you still include type="text/javascript"?
You can just use <script>...</script>
There is one more attribute available: <script charset="utf-8">
Specifying a charset for a SCRIPT
is useful only if it differs from the page. The page charset is defined in the HEAD
tag by:<meta charset="..." />
And in the quest of removing unnecessary things: To avoid the onload
, document...ready
and friends, just place the SCRIPT
tag that starts your app at the end of the BODY
tag. All JS files in the HEAD
and the DOM
are loaded and ready to be used.
<html>
<head>
<script src="lib.js"></script>
</head>
<body>
...
<script>
//start your app here
</script>
</body>
</html>
1: No. The onload browsers that don't support JavaScript and still exist just ignore what's in the script tag. 2: No. It's depreciated. The only use what to say to IE you were using JavaScript and not VBScript but nowadays it just assumes it. 3: With HTML5, you don't need it anymore in order to pass the validator but even before, it was useless. More informations : https://developer.mozilla.org/En/HTML/Element/Script
The only one thing about script tags nowadays is you shouldn't use the stand-alone form.
精彩评论