jquery document width
I am using to set a div as mask for the entire page.
$(document).width();
But this behaves differently between IE and Firefox. In IE it gives 796 whereas in firefox it gives 789. When i apply the mask's width as $(document).width();
In firefox the mask is fit to the screen. But in IE, an extra scroll bar appears below.
I want the mask to fit the screen. Please help me handling this.
window.width() and 100% wouldn't help when i resize the window. I cant use $('body') in place coz, i need开发者_如何学C to calculate the height in the same manner.
Thanks in advance.
This is literately days of trial and error and searching all the world
Using pureJS because not even jquery reports it properly! but need jquery to identify the browser . I used this to measure body in an iframe- to avoid scrollbars on cross domains communications.. you could tweak it a bit. but the core is there
if ( $.browser.msie ) {
var thisH = thisFrame.scrollHeight;
var thisW = thisFrame.scrollWidth;
}
else if ( $.browser.opera )
{
var thisW = thisFrame.scrollWidth;
if (iframe.clientWidth > thisW ) {
thisW = 660; //These are custom- you can ignore it
}
var thisH = thisFrame.scrollHeight;
if (iframe.clientHeight > thisH ) {
thisH = 550; //These are custom- you can ignore it
}
}
//All other clients
else
{
var thisW = thisFrame.scrollWidth;
if (iframe.clientWidth > thisW ) {
thisW = 660; //These are custom- you can ignore it
}
var thisH = $(thisFrame).height();
if (iframe.clientHeight > thisH ) {
thisH = 550; //These are custom- you can ignore it
}
}
http://www.javascripter.net/faq/browserw.htm
The following code sets the variables winW and winH to the actual width and height of the browser window, and outputs the width and height values. If the user has a very old browser, then winW and winH are set to 630 and 460, respectively.
var winW = 630, winH = 460;
if (document.body && document.body.offsetWidth) {
winW = document.body.offsetWidth;
winH = document.body.offsetHeight;
}
if (document.compatMode=='CSS1Compat' &&
document.documentElement &&
document.documentElement.offsetWidth ) {
winW = document.documentElement.offsetWidth;
winH = document.documentElement.offsetHeight;
}
if (window.innerWidth && window.innerHeight) {
winW = window.innerWidth;
winH = window.innerHeight;
}
精彩评论