Javascript Window Tiling

by Mark Wiseman on August 4th, 2009 | Posted in Revium Sandbox | Read the comments

We currently have a customer who needs to track numerous items in realtime via the web.

They wanted to be able to:

  • Watch each item in it’s own pop-up window
  • As they open each new window tile it should be placed along side the next (to eliminate manual positioning)
From this To this
Standard Windows Tiled Windows

Because i went through a few iterations from rediculously complex to fairly to simple i thought i would share the result here.

//keep track of how many windows are open
var win_open = 0;

function openAndTileWindow(url) {
	var pad_left = 20;
	var pad_top = 90;
	var width = 416;
	var height = 350;

	//how many windows can we fit on the screen?
	//i.e. will return the width of the left most screen and firefox will return the width of the current screen.
	//we add pad_left to screen.width because we want the first items flush against the screen
	var max_on_row = Math.floor((screen.width + pad_left) / (width + pad_left));

	//Determine which row this item will be displayed on
	var row = Math.ceil((win_open + 1) / max_on_row) - 1;

	//Determine the position in the current row to display this item
	var pos = win_open - (row * max_on_row);

	//Get the left most position
	var availLeft = 0;
	if (screen.availLeft != undefined)
		availLeft = screen.availLeft; //mozilla only

	//we add padding if it isn't in the first position because we don't want to windows to overlap
	var left = availLeft + (pos * width);
	if (pos > 0)
		left += pad_left * pos;

	//make sure if we reach the bottom of the screen we start at the top again
	while (row > max_rows - 1)
		row -= max_rows;

	//get the top position of the new window
	var top = (row * height);
	if (row > 0)
		top += pad_top;

	window.open(url, 'tile', "toolbar=0,menubar=0,width="+width+",height="+height+",left="+left+",top="+top+",resizable=1");

	win_open += 1;
}

Note: On a single monitor this code works exactly the same for both IE and Firefox. When you have dual monitors it is slightly different. Firefox will work the same in both instances. All the popup windows will always open up on the same monitor on the page. With IE however, the popups will always open up on the Primary Monitor.

Related posts:

  1. Creating deployment packages in SVN
  2. Windows 7 + VB6 + Standard User’s + The Registry = Arg!

« Asp.Net and Aweber

Limiting LINQ String Field Lengths »

One Response to “Javascript Window Tiling”

  1. Brian says:
    October 1, 2009 at 1:13 am

    Had to add ‘var max_rows = 2;’ to get this to work.

    Example:

    var pad_left = 20;
    var pad_top = 90;
    var width = 416;
    var height = 350;
    var max_rows = 2;

    Other than that, works great. I customized it to work how I needed.

    Thanks,
    Brian

Leave a Reply

Click here to cancel reply.

Recent Articles

  • 10 Tips for user acceptance testing of web applications
  • Popular Content Management Systems
  • ASP.NET MVC [HandleError] and logging
  • VMWare hard lessons
  • Linq – SubmitChanges does not work
  • Using FourSquare for Marketing
  • ASP.NET Button – prevent double clicks part 2
  • The easy way to clear floated elements

Twitter

  • 50 Useful Tools & Resources For Web Designers <http://www.smashingmagazine.com/2010/07/26/50-useful-tools-and-resources-for-web-designers/> 3 days ago
  • Tourism Australia has launched a free "Go Ashes" app for iPhone to promote England vs Australia cricket series 4 days ago
  • #YouTube competition, on 24 July capture you Life In A Day http://youtu.be/tZFbDY3-eG4 1 week ago
  • More updates...

Revium Logo

  • Home
  • About
  • Expertise
  • Showcase
  • Contact

  • news
  • blog
  • sandbox
  • twitter
  • facebook
  • rss
Bookmark and Share

We are Revium, hear us roar!

The news.

23 Apr

Revium sponsors IIA CEO luncheon on 2010 Challenges

Last Wednesday 14th April Revium hosted a CEO luncheon for the Internet Industry Association (IIA). Revium have been long time supporters of the IIA and…

Continue reading
View archive

The blog.

11 Jun

VMWare hard lessons

Well, I learned a hard lesson today when I decided to give more hard drive space to one of our virtual machines. We run…

Continue reading
View archive

The sandbox.

02 Jul

10 Tips for user acceptance testing of web applications

1. Draw up a testplan Many testers would like to skip this step, but it is essential for structured testing. It depends of course on the…

Continue reading
View archive

eNewsletter.

 

© Copyright 2010. All Rights Reserved.

Revium Pty Ltd

e / info@revium.com.au t / Work +61 3 9429 2000

Find us: web development, seo

Disclaimer and privacy Revium Pty Ltd

10 Harvey Street
Richmond, Victoria, 3121 Australia
View map

Logo Partner MicrosoftLogo Partner KenticoLogo Partner IiaLogo Partner Iia RibLogo Partner Acs