Link to home
Start Free TrialLog in
Avatar of aldwins
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.clientHeight)
    docHeight = document.documentElement.scrollHeight;
  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.offsetHeight);

  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
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aldwins
aldwins

ASKER

perfect,

thanks
Glad I could help.  Thanks for the A. :^)

Cd&