JavaScript DHTML/Window Browser/Screen
Содержание
- 1 Detect the client"s screen
- 2 "deviceXDPI" Example
- 3 "deviceYDPI" Example
- 4 Displaying the Properties of the Screen Object
- 5 "height-2" Example
- 6 "logicalXDPI" Example
- 7 "logicalYDPI" Example
- 8 Screen "availHeight"
- 9 Screen availLeft
- 10 Screen "availTop"
- 11 Screen "availWidth"
- 12 Screen "bufferDepth" Example
- 13 Screen "colorDepth" Example
- 14 Screen font Smoothing Enabled
- 15 Screen update Interval
- 16 Screen "width" Example
- 17 Using the const Keyword
Detect the client"s screen
<html>
<body>
<script type="text/javascript">
document.write("Screen resolution: ")
document.write(screen.width + "*" + screen.height)
document.write("<br>")
document.write("Available view area: ")
document.write(screen.availWidth + "*" + screen.availHeight)
document.write("<br>")
document.write("Color depth: ")
document.write(screen.colorDepth)
document.write("<br>")
</script>
</body>
</html>
"deviceXDPI" Example
<html>
<body>
<button onclick="alert(screen.deviceXDPI);">device XDPI</button>
<button onclick="alert(screen.deviceYDPI);">device YDPI</button>
</body>
</html>
"deviceYDPI" Example
<html>
<body>
<button onclick="alert(screen.deviceXDPI);">device XDPI</button>
<button onclick="alert(screen.deviceYDPI);">device YDPI</button>
</body>
</html>
Displaying the Properties of the Screen Object
<HTML>
<HEAD>
<TITLE>Test</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function displayScreenProperties() {
with(document) {
write("<B>height: </B>")
writeln(screen.height+"<BR>")
write("<B>width: </B>")
writeln(screen.width+"<BR>")
write("<B>colorDepth: </B>")
writeln(screen.colorDepth+"<BR>")
}
}
displayScreenProperties()
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
"height-2" Example
<html>
<body>
<button onclick="alert(screen.height);">Screen Height</button>
</body>
</html>
"logicalXDPI" Example
<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>
"logicalYDPI" Example
<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>
Screen "availHeight"
<html>
<body>
<button onClick=" alert(screen.availHeight);">Available Height</button>
</body>
</html>
Screen availLeft
<html>
<body>
<button onclick="alert(screen.availLeft);">AvailLeft</button>
</body>
</html>
Screen "availTop"
<html>
<body>
<button onclick="alert(screen.availTop);">AvailTop</button>
</body>
</html>
Screen "availWidth"
<html>
<body>
<button onClick="alert(screen.availWidth);">Available Width</button>
</body>
</html>
Screen "bufferDepth" Example
<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>
Screen "colorDepth" Example
<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>
Screen font Smoothing Enabled
<html>
<body>
<script language="JavaScript">
function function1() {
alert(screen.fontSmoothingEnabled);
}
</script>
<button onclick="function1();">Font Smoothing Enabled</button>
</body>
</html>
Screen update Interval
<html>
<body>
<button onclick="screen.updateInterval=2000; alert(screen.updateInterval);">
Update Interval
</button>
</body>
</html>
Screen "width" Example
<html>
<body>
<button onclick="alert(screen.width);">Screen Width</button>
</body>
</html>
Using the const Keyword
<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()">
<H1>The const keyword</H1>
<HR>
<TABLE ID="temps">
<TR><TH>City<TH>Temperature</TR>
<TBODY ID="display">
</TBODY>
</TABLE>
</BODY>
</HTML>