Thứ Tư, 21 tháng 8, 2013

Deprecated Syntax

When the <script>element was originally introduced, it marked a departure from traditional HTML parsing. Special rules needed to be applied within this element, and that caused problems for browsers that didn’t support JavaScript (the most notable being Mosaic). Nonsupporting browsers would output the contents of the <script>element onto the page, effectively ruining the page’s appearance.Netscape worked with Mosaic to come up with a solution that would hide embedded JavaScript code from browsers that didn’t support it. The final solution was to enclose the script code in an HTML comment, like this:
<script><!--function sayHi(){
alert(“Hi!”);
}
//--></script>
Using this format, browsers like Mosaic would safely ignore the content inside of the <script>tag, and browsers that supported JavaScript had to look for this pattern to recognize that there was indeed JavaScript content to be parsed.Although this format is still recognized and interpreted correctly by all web browsers, it is no longer necessary and should not be used. In XHTML mode, this also causes the script to be ignored because it is inside a valid XML comment.

Không có nhận xét nào:

Đăng nhận xét