Showing posts with label ajaxcontroltoolkit. Show all posts
Showing posts with label ajaxcontroltoolkit. Show all posts

Monday, 15 November 2010

Using javascript to create full screen windows in ASP .Net

My current role at DatabridgeMiS involves creating a web version of existing software, which can be tricky when trying to create the same functionality of popup windows that can be maximized to full screen.

When using the Ajax Control Toolkit I can use the ModalPopupExtender to create simple popup windows by setting the target to a panel that is invisible by default. I can set the panels width and height to control the size of my popup window.

However, I wanted to be able to achieve full width and height but I found using percentages of 100% for both and the body worked ok to some extent but looked confusing in places plus I wanted specific sizing for some items.

So I decided to create my own code to perform this action myself. I already had jquery attached to my page so I could use the document.Ready function to insert my code.

First I needed to find the width and height of the current viewport:

var viewportwidth;
var viewportheight;

if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerWidth;
viewportheight = window.innerHeight;
}
else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) {
viewportheight = document.documentElement.clientHeight;
viewportwidth = document.documentElement.clientWidth;
}
else {
viewportheight = document.getElementsByTagName('body')[0].clientHeight;
viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
}

The code above performs different checks as different browsers use different methods of obtaining the viewport information and using only one method wouldn't work across the board. Next I used a jquery style function to find all 'panels' that I had put a class of 'fullscreen' on:

$('.fullscreen').each(function (i) {
$(this).width(viewportwidth);
$(this).height(viewportheight);
});

This then regardless of browser makes my popup full screen (although watch out for margin or padding settings that could enlarge it).

Then I simply used other jquery style functions to set elements height/width within the popup by simply subtracting the viewport settings. Have a play yourself and check it out on different browsers and screens, works brilliantly.