Four methods of web page detection

Source: Internet
Author: User
Web page on the Internet to see a lot of home page has such a hint: we recommend that you use IE4. 0 Use 800x600 resolution to the page. In fact, in the Web page in the main part of that and between and find a suitable location, add a very simple little JavaScript statement can detect the browser type, resolution, color and make suggestions to make the browser's browsing environment in line with the site's best browsing environment, not better. Here describes the detection of screen resolution and color number of JavaScript source code is not found elsewhere, you can not miss Yo!

One: Detecting browser types and versions
<script language= "javascript1.2" >
<!--
document.write ("You are using the browser is" +navigator.appname+ "" +navigator.appversion);
-->
</script >

Second: Detect the browser type, version and further determine whether the browser of browsers to meet the best browsing environment in your station, and put forward corresponding suggestions
<script language= "javascript1.2" >
<!--
var vn= "Microsoft Internet Explorer";
var va=4;
if (navigator.appname!=vn| | parseint
(navigator.appversion) 〈va);
document.write ("You are using the browser is" +vn+ "" +navigator.appversion);
if (NAVIGATOR.APPNAME!=VN) document.write
("It is recommended that you use" +vn+ "to browse for the best browsing effect.) ");
Else
if (parseint (navigator.appversion) 〈va) document.write
("The version is too old!" We recommend that you update your browser as soon as possible. ");
else document.write (", in line with the site's best browsing environment." ");
-->
</script >
----Description: statement "var vn=" Microsoft Internet Explorer; is to set the best browser name.
----statement "Var va=4;" is set to the lower limit of the browser version, please set according to your actual situation.

Third: Detect screen resolution, and propose the best browsing recommendations
<script language= "javascript1.2" >
<!--
var s=800;
if (screen.width!=s);
document.write ("Your screen resolution is" +screen.width+ "*" +screen.height);
if (screen.width!=s) document.write
(", not the best resolution, we recommend that you adjust the screen resolution to 800*600 Browse this page.") ");
else document.write (", in line with the site's best browsing environment." ");
-->
</script >
----Description: statement "var s=800;" Set the best browsing screen resolution width, according to your actual situation.

Four: Detect the screen color of the viewer, and propose the best browsing suggestions
<script language= "javascript1.2" >
<!--
var c, cv=16;
if (cv!= "Netscape") c=screen.colordepth;
else c=screen.pixeldepth;
var cs=c;
if (c==4) cs= "4-bit 16-color";
if (c==8) cs= "8-bit 256-color";
if (c==16) cs= "16-bit enhanced color";
if (c >16) cs=cs+ "bit true Color";
if (C〈CV);
document.write ("Your screen color is" +cs);
if (C〈CV)
document.write (", Too low!") The background of this site is difficult to see, please adjust the color to 16-bit enhanced color browsing this page. ");
Else
document.write (", meet the best browsing environment of the site." ");
-->
</script >
----Description: statement "CV=16;" Set the lower limit of the best color, please set according to your actual situation.

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.