There is a frame, how do you know how much frame content is scrolled when you click a button?

    2 answers 2

    iframe is a separate window object. You need to first try to access iframe.window.document , and then get the scrollTop value of the scrollTop element in this iframe . If the src iframe satisfies the same origin policy - then everything is ok, and if the iframe is from a different domain, then nothing happens.

     var fr = document.getElementById('iframeID'); var fw = (fr.contentWindow || fr.contentDocument); if ( !!!fw.document) fw = fw.defaultView; var IFRAME_SCROLL = fw.document.getElementsByTagName('BODY')[0].scrollTop; 

    Something like this here. Still need to take into account the position elements.

    • what you need, thank you - shol

    If you know the initial value of height() , then you can compare:

     $('#button').click(function(){ alert('На данный момент height: ' + $('#object').height()); }); 

    well, or if it helps you, then scroll can be tracked like this:

     $('#scroll').scroll(function(){ alert('Был использован scroll'); }); 
    • I need to on pure js and precisely for iframe - shol
    • Than jQuery didn't please you in iframe? - k0mar
    • what difference does it make me for the sake of that I don’t need to connect this library, I have everything on pure js - shol