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.
No comments:
Post a Comment