get the dimension of my document using JavaScript

to get the dimension of my document.

// javascript
var screen_width = null;
var screen_width = null;
screen_width = document.body.offsetWidth;
alert('Get IT');
screen_height = document.body.offsetHeight;
document.forms[0].txt_width.value = screen_width;
document.forms[0].txt_height.value = screen_height;

But the above script will fire only once the first time when the page is loaded.

do to execute this script every time the user resize window of the browser, use the following code part

if (self.innerWidth)
frameWidth = self.innerWidth;
frameHeight = self.innerHeight;
else if (document.documentElement && document.documentElement.clientWidth)
frameWidth = document.documentElement.clientWidth;
frameHeight = document.documentElement.clientHeight;
else if (document.body)
frameWidth = document.body.clientWidth;
frameHeight = document.body.clientHeight;
else return;
if (self.screen.width < frameWidth *2 self.screen.height < frameHeight *2)
newWidth = self.screen.width/2;
newHeight = self.screen.height/2;
if (document.layers)
tmp1 = parent.outerWidth - parent.innerWidth;
tmp2 = parent.outerHeight - parent.innerHeight;
newWidth -= tmp1;
newHeight -= tmp2;
alert('No resize necessary');


Popular posts from this blog

ASP.NET website "Cannot read configuration file due to insufficient permissions" in IIS 7 and Windows Server 2008

Error occurred in deployment step 'Install app for SharePoint': The System Account cannot perform this action.

Windows Server AppFabric: installation error , While installing SharePoint prerequisite installer