JavaScript Instance Tutorial (12) Hiding script code

Source: Internet
Author: User
javascript| Tutorial

Use JavaScript to hide JavaScript from old browsers

For JavaScript beginners, they often forget to hide JavaScript code in old browsers, such as Netscape Navigator 1.12. You might ask why you want to hide it? The simple reason is that the old browser does not support JavaScript. If you don't do the right thing, the old browser will display your JavaScript source code, just like HTML, so you have to hide the JavaScript. Specifically, you can use some HTML statements to easily hide JavaScript from the old browser.

The specific code is as follows:

<script language= "JavaScript" >

<!--alert ("JavaScript is running!");

--> </SCRIPT>

JavaScript-enabled browsers will interpret this code, and the old browser will only treat it as HTML, and it has been commented, so it has been able to hide JavaScript code. You may want to add some text to the <NOSCRIPT> tab, which allows non-JavaScript users to see what they are missing:

<noscript>this'll only show up in older Non-javascript capable browsers</noscript>

In fact, there are very few browsers that do not support JavaScript, even if there are few people using that kind of browser, which can be ignored during normal production. But then again, for a programmer, it's important to develop good programming habits, and of course it's from small things.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.