-2

Is there a way to detect presence of scrollbar in the Dom measuring body height and window height in JavaScript? I want the syntax.

Sayan Sahoo
  • 65
  • 1
  • 4
  • you might be looking for https://stackoverflow.com/questions/681087/how-can-i-detect-a-scrollbar-presence-using-javascript-in-html-iframe – Rahul Nov 11 '19 at 07:18

1 Answers1

1

You can check if an element has scrollbar using scrollHeight property of the element

if (element.offsetHeight < element.scrollHeight)

PS: if you don't know the overflow property of the element, you might wanna add additional check for overflow

if ((element.offsetHeight < element.scrollHeight && element.style.overflowY !== 'hidden') || element.style.overflowY === 'scroll')
AvcS
  • 2,263
  • 11
  • 18