www.webdeveloper.com
Results 1 to 6 of 6

Thread: Scrollbar is visible?

  1. #1
    Join Date
    Jan 2018
    Posts
    19

    Scrollbar is visible?

    hi all,

    How can I check, if browser scrollbar is visible or not?

    Thx,
    Aykut

  2. #2
    Join Date
    Jan 2018
    Posts
    19
    Update:

    I mean with scrollbar, the scrollbar of an iframe.

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,762
    I did a quick google search, you might want to try a search for finding out if an iframe has scroll bars in JavaScript and see what popps up.

    What I found was this offering which I have no idea if it works, perhaps you could confirm if it does or not:
    Code:
    var iframe=document.getElementById("iframeId");
    var scrollbars = { vertical:  (iframe.contentWindow.document.documentElement.scrollHeight > iframe.contentWindow.document.documentElement.offsetHeight ? 1 : 0 ),
    horizontal: (iframe.contentWindow.document.documentElement.scrollWidth > iframe.contentWindow.document.documentElement.offsetWidth ? 1 : 0) };
    where iframeId is the id attribute of the target iframe.

    So the result is a variable with two properties, both values in the properties will be a 1 or a 0 where 1 is a true or a false is 0, you could try it and if it works then you possibly have a winner.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Jan 2018
    Posts
    19
    Hi,

    the code you provided is "almost" perfect

    The following code works for me.

    function checkScrollBarActive() {

    var iframe= document.getElementById("myIFrame");
    var scrollbars = { vertical: (iframe.contentWindow.document.documentElement.scrollHeight > (window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight) ? 1 : 0 ),
    horizontal: (iframe.contentWindow.document.documentElement.scrollWidth > (window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth) ? 1 : 0) };

    alert("horizontal : " + scrollbars["horizontal"]+"\n"+"vertical : " + scrollbars["vertical"])
    }

  5. #5
    Join Date
    Jan 2018
    Posts
    19
    Many Thanks ...
    - to you and
    - to https://stackoverflow.com/questions/...llbars-visible

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,762
    Accessing an object property is also as easy as alert("horizontal : " + scrollbars.horizontal +"\r\n"+"vertical : " + scrollbars.vertical ) and remember that the majority of web users are using windows that requires \r\n combination for a new line.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"