aldwins
asked on
Firefox bug: innerWidth, presence of vertical scrollbar
Hi,
I need to position a div in firefox but when giving the innerWidth of the window, firefox doesn’t take into consideration if the vertical scroll bar is present or not, so when the vertical scrollbar appears, the size of the window is reduced while window.innerWidth stays constant, therefore my div is shifted to the left…
I’ve found dakyd’s function to detect the presence of the vertical scrollbar but unfortunately it it does not work 100% like it should, in some cases it gives error because of the fudgeFactor that does not work for all combinations of window size:
https://www.experts-exchange.com/questions/21435532/Firefox-bug-offsetWidth-and-vertical-scroll.html?query=Firefox+bug&clearTAFilter=true
function checkScroll()
{
var fudgeFactor = document.all? 4: 6; // Moz only
var docHeight, totalHeight;
if (document.all && document.documentElement && document.documentElement.c lientHeigh t)
docHeight = document.documentElement.s crollHeigh t;
else if (document.all)
docHeight = document.body.scrollHeight ;
else
docHeight = document.height;
docHeight = parseInt(docHeight) + fudgeFactor;
if (self.innerHeight)
totalHeight = parseInt(self.innerHeight) ;
else
totalHeight = parseInt(document.body.off setHeight) ;
if (docHeight > totalHeight)
return 1;
else
return 0;
}
Is there another way to obtain the “real” inner width of a firefox window ?
Thanks
I need to position a div in firefox but when giving the innerWidth of the window, firefox doesn’t take into consideration if the vertical scroll bar is present or not, so when the vertical scrollbar appears, the size of the window is reduced while window.innerWidth stays constant, therefore my div is shifted to the left…
I’ve found dakyd’s function to detect the presence of the vertical scrollbar but unfortunately it it does not work 100% like it should, in some cases it gives error because of the fudgeFactor that does not work for all combinations of window size:
https://www.experts-exchange.com/questions/21435532/Firefox-bug-offsetWidth-and-vertical-scroll.html?query=Firefox+bug&clearTAFilter=true
function checkScroll()
{
var fudgeFactor = document.all? 4: 6; // Moz only
var docHeight, totalHeight;
if (document.all && document.documentElement && document.documentElement.c
docHeight = document.documentElement.s
else if (document.all)
docHeight = document.body.scrollHeight
else
docHeight = document.height;
docHeight = parseInt(docHeight) + fudgeFactor;
if (self.innerHeight)
totalHeight = parseInt(self.innerHeight)
else
totalHeight = parseInt(document.body.off
if (docHeight > totalHeight)
return 1;
else
return 0;
}
Is there another way to obtain the “real” inner width of a firefox window ?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad I could help. Thanks for the A. :^)
Cd&
Cd&
ASKER
thanks