• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

JavaScript Screen Object

April 9, 2014 //  by Krishna Srinivasan//  Leave a Comment

The screen object specifies information about dimensions of the user’s screen and display settings. It is special object for inspecting properties of the screen on which the current window is being rendered. There is no public standard that applies to the screen object, but all major browsers support it.

 Javascript Screen Object Properties

The following are the properties of Screen object:

  • availWidth: It returns available width of the screen in the pixels for application windows.
  • availHeight: It returns available height of the screen in the pixels for application windows.
  • colorDepth: It retrieves number of bits per pixel used for colors on the screen.
  • pixelDepth: It retrieves number of bits per pixel used for screen color resolution on the screen.
  • width: It returns horizontal resolution of the screen in pixels.
  • height: It returns vertical resolution of the screen in pixels.
  • availLeft: It returns available area of the left side of the screen for application windows.
  • availTop: It returns available area of the top side of the screen for application windows.

Javascript Screen Object Example

<!DOCTYPE html>
<head>
<meta charset="ISO-8859-1">
<title>Screen Object</title>
</head>
<body>
	<script type="text/javascript">
	document.write("Total height is:" + screen.height + "<br>");
	document.write("Total width is:" + screen.width + "<br>");
	document.write("Avaialble width is:" + screen.availWidth + "<br>");
	document.write("Avaialble height is:" + screen.availHeight + "<br>");
	document.write("Color depth is:" + screen.colorDepth + "<br>");
	document.write("Color resultion is:" + screen.pixelDepth + "<br>");
	</script>
</body>
</html>
  • <script type=”text/javascript”> tag is used to define client side script which uses attribute type for specifying MIME type.
  • document.write(“Total height is:” + screen.height);line returns height of the screen.
  • document.write(“Total width is:” + screen.width);line specifies width of the screen.
  • document.write(“Avaialble width is:” + screen.availWidth);line specifies available width of the screen in the pixels.
  • document.write(“Avaialble height is:” + screen.availHeight);line specifies available height of the screen in the pixels.
  • document.write(“Color depth is:” + screen.colorDepth);line specifies number of bits per pixel used for colors on the screen.
  • document.write(“Color resultion is:” + screen.pixelDepth);line specifies number of bits per pixel used for screen color resolution.

Javascript Screen Object Demo

  • Save the file as JSscreen_example.html in your system.
  • Just open the file in the browser, you will see the below picture in the browser.

When the execution process is completed successfully we will get the following output:

Javascript Screen Object

Category: JavaScriptTag: JavaScript Tutorials

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Previous Post: « How To Get Operating System using JavaScript
Next Post: JavaScript Location Object »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact