JavaScript DHTML/Window Browser/Screen

Материал из Web эксперт
Версия от 10:28, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Detect the client"s screen

   <source lang="html4strict">

<html> <body> <script type="text/javascript">

   document.write("Screen resolution: ")
   document.write(screen.width + "*" + screen.height)
   document.write("
") document.write("Available view area: ") document.write(screen.availWidth + "*" + screen.availHeight) document.write("
") document.write("Color depth: ") document.write(screen.colorDepth) document.write("
")

</script> </body> </html>


      </source>
   
  


"deviceXDPI" Example

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.deviceXDPI);">device XDPI</button> <button onclick="alert(screen.deviceYDPI);">device YDPI</button> </body> </html>


     </source>
   
  


"deviceYDPI" Example

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.deviceXDPI);">device XDPI</button> <button onclick="alert(screen.deviceYDPI);">device YDPI</button> </body> </html>


     </source>
   
  


Displaying the Properties of the Screen Object

   <source lang="html4strict">

<HTML> <HEAD> <TITLE>Test</TITLE> <SCRIPT LANGUAGE="JavaScript"> function displayScreenProperties() {

with(document) {
 write("height: ")
 writeln(screen.height+"
") write("width: ") writeln(screen.width+"
") write("colorDepth: ") writeln(screen.colorDepth+"
") }

} displayScreenProperties() </SCRIPT> </HEAD> <BODY> </BODY> </HTML>

      </source>
   
  


"height-2" Example

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.height);">Screen Height</button> </body> </html>


     </source>
   
  


"logicalXDPI" Example

   <source lang="html4strict">
   

<html> <body> <script language="JavaScript"> function function1() {

   var m = screen.logicalXDPI;
   var n = screen.logicalYDPI;
   alert("Screen XDPI =\n"+m); 
   alert("Screen YDPI =\n"+n); 

} </script> <input type="button" value="Click me" onclick="function1();"> </body> </html>


     </source>
   
  


"logicalYDPI" Example

   <source lang="html4strict">
   

<html> <body> <script language="JavaScript"> function function1() {

   var m = screen.logicalXDPI;
   var n = screen.logicalYDPI;
   alert("Screen XDPI =\n"+m); 
   alert("Screen YDPI =\n"+n); 

} </script> <input type="button" value="Click me" onclick="function1();"> </body> </html>


     </source>
   
  


Screen "availHeight"

   <source lang="html4strict">
   

<html> <body> <button onClick=" alert(screen.availHeight);">Available Height</button> </body> </html>


     </source>
   
  


Screen availLeft

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.availLeft);">AvailLeft</button> </body> </html>


     </source>
   
  


Screen "availTop"

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.availTop);">AvailTop</button> </body> </html>


     </source>
   
  


Screen "availWidth"

   <source lang="html4strict">
   

<html> <body> <button onClick="alert(screen.availWidth);">Available Width</button> </body> </html>


     </source>
   
  


Screen "bufferDepth" Example

   <source lang="html4strict">
   

<html> <head> <script language="JavaScript">

   function function1() {
       if (navigator.appName.indexOf("Microsoft") != -1) {
           var m = screen.bufferDepth;
           alert("The buffering for this screen is "+m);
       } else {
           alert("Netscape: no default for buffering depth"); 
       }
   } 
   function function2() {
       screen.bufferDepth = -1;
       var m = screen.bufferDepth;
       alert("The buffering depth for this screen has been changed to "+m); 
   } 

</script> </head> <body> <input type="button" value="No Buffering" onClick="function1();"> <input type="button" value="Same as Color Depth" onClick="function2();"> </body> </html>


     </source>
   
  


Screen "colorDepth" Example

   <source lang="html4strict">
   

<html> <head> <script language="JavaScript">

   function function1() {
       var m = screen.colorDepth;
       alert("The color depth of the screen is "+m+" bits per pixel"); 
   } 

</script> </head> <body bgcolor="#EEEEEE" ondblclick="function1();"> </body> </html>


     </source>
   
  


Screen font Smoothing Enabled

   <source lang="html4strict">
   

<html> <body> <script language="JavaScript">

   function function1() {
       alert(screen.fontSmoothingEnabled);
   }

</script> <button onclick="function1();">Font Smoothing Enabled</button> </body> </html>


     </source>
   
  


Screen update Interval

   <source lang="html4strict">
   

<html> <body> <button onclick="screen.updateInterval=2000; alert(screen.updateInterval);"> Update Interval </button> </body> </html>


     </source>
   
  


Screen "width" Example

   <source lang="html4strict">
   

<html> <body> <button onclick="alert(screen.width);">Screen Width</button> </body> </html>


     </source>
   
  


Using the const Keyword

   <source lang="html4strict">

<HTML> <HEAD> <TITLE>const(ant)</TITLE> <SCRIPT LANGUAGE="JavaScript"> const FREEZING_F = 32 var cities = ["A", "B", "C", "D", "E"] var tempsF = [33, 12, 20, 40, 75] function showData() {

   var tableData = ""
   for (var i = 0; i < cities.length; i++) {
       tableData += "<TR><TD>" + cities[i] + "</TD><TD "
       tableData += (tempsF[i] < FREEZING_F) ? "CLASS="cold"" : ""
       tableData += ">" + tempsF[i] + "</TR>"
   }
   document.getElementById("display").innerHTML = tableData

} </SCRIPT> </HEAD> <BODY onLoad="showData()">

The const keyword


<TBODY ID="display"> </TBODY>

CityTemperature

</BODY> </HTML>


      </source>