On the webpage, I need to check if there is a horizontal scrollbar or not (so I programmatically change the css of some other element). Is there any way to get this information using jquery (or pure javascript)?
I tested
function isHorizontalScrollbarEnabled() {
return $(document).width()!=$(window).width();
}
but it doesn't seem to work with all browsers (for example, it doesnβt work with the latest Samsung phone that I tested). I need it to work with all browsers, including the latest mobile devices.
Thank!
EDIT 1
I tested the solutions provided by plalx and laconbass, tested IE8, Firefox, Chrome and iPad. Works with IE, Firefox, and Chrome, but not the way I want on an iPad.
: , , iPad, , document, window document.body ( Samsung, ).
, :
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<title>test</title>
</head>
<body>
<div style="width: 500px; background: red;" id="test">click here to test</div>
<script type="text/javascript">
var i = 1;
$("#test").click(function(){
$(this).html("Test #" + (i++)
+ "<br>document width=" + $(document).width() + ", windows width=" + $(window).width()
+ "<br>document width=" + $(document).width() + ", body width=" + $(document.body).width()
);
});
</script>
</body>
</html>
, , / , iPad?