How to identify Netscape 6 browsers with JavaScript

Source: Internet
Author: User
The JavaScript code that we used to identify browsers is generally as follows:

<script language= "JavaScript" >
<!--
if (document.all) {//ie
Alert ("Your browser is Internet Explorer");
}
else if (document.layers) {//ns
Alert ("Your browser is Netscape Navigator");
}
else {
Alert ("Cannot detect your browser");
}
-->
</SCRIPT>

The above code can work well in Netscape6, and now when you use Netscape6, it will pop up the "Browser not detected" information, that is, can not correctly identify the Netscape6.
This is because Netscape 6 does not support document.all and does not support document.layers. Netscape 6 supports document.getElementById. But IE also supports
This method, so the instrumentation code must be rewritten to accommodate Netscape6.

Here is the detection code:

<script language= "JavaScript" >
<!--
if (document.all) {//ie
Alert ("Your browser is Internet Explorer");
}
else if (document.layers) {//ns
Alert ("Your browser is Netscape Navigator");
}
else if (document.getElementById) {//increase this row to detect whether Netscape 6
Alert ("Your browser is Netscape 6");
else {
Alert ("Cannot detect your browser");
}
-->
</SCRIPT>

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.