indiWiz.com
SiteSearch:
Jump:

Site Map | WizTools.org | jCraze Blog
Web Developer's Den!
Home : WDD : JavaScript
This Article...
Print Version
Add Comment
View Comments
JavaScript
The Bare Facts
Rollover Script
Script Windows
Status Message
Time Sensibility of JavaScript
JavaScript and Frames
Expandable Menus
Cursor Effects!
Regular Expressions Reference
JavaScript Screen Size
JavaScript HTMLize (Using Regular Expressions)
Java Script Dynamic Time Update
Sections

Commniquè
Sign Guestbook!
Read Guestbook!
MailMe!

JavaScript Screen Size

Ever wondered how to find the screen resolution of the user? It is very simple in JavaScript:


<script language="javascript">
var w = screen.width; // Get the width of the screen
var h = screen.height; // Get the height of the screen
</script>

So want to find your screen resolution? Find!

Opening A Centered Window

So wouldn't you like to use the above trick for some useful purpose? How about opening a centered window? Use this code:


<script language="javascript">
function openCentered(){
	var w = screen.width; // Get the width of the screen
	var h = screen.height; // Get the height of the screen

	// The size of the Window
	var win_width = w - 350;
	var win_height = h - 250;

	// Where to place the Window
	var left = (w - win_width)/2;
	var top = (h - win_height)/2;

	var features = 'width='+win_width+',height='+win_height
	features += ',top='+top+',left='+left+',screenX='+left+',screenY='+top;

	var win = window.open('', '', features);
	win.document.write('<html><head><title>JavaScript Eg.</title></head>');
	win.document.write('<body><h2>indiWiz.com JavaScript Example</h2></body></html>');
	win.document.close();
}
</script>

Call this function.

User Comments

Add Comment

[Quick Stats: Number of main threads: 0, Number of sub-threads: 0]

Sign Guestbook | Who is Subhash?
The contents of this site are copyright© 2000-2008, indiWiz.com. All Rights Reserved.