Js determines whether the page inside the iframe scrolls to the bottom to trigger an event

  • 2020-03-30 02:22:16
  • OfStack

Before, there was a requirement to determine whether the page in the iframe scrolls to the bottom of the trigger event. I found a lot of information on the Internet, which were all under the current page, so I simply researched myself and found a solution.

ClientHeight: the height of this element, the height of the whole space

OffsetHeight: the height of the element content

ScrollTop: the length of the scrollbar that can be scrolled

Here is the source code
<iframe src="~/Files/3.html" id="iframepage" width="825" onload="func()"></iframe> 
<script type="text/javascript"> 
function func() { 
var ifm = document.getElementById("iframepage"); 
ifm.height = window.document.body.clientHeight - 100; 
<!-- in chrome There are compatibility issues, FF and IE10 No problem, the website says chrome access iframe Do you know what's going on in a server environment --> 
window.document.getElementById("iframepage").contentWindow.onscroll = function aaa() { 
var ifm = document.getElementById("iframepage").contentWindow.document.documentElement; 
if (ifm.scrollTop == ifm.scrollHeight - ifm.clientHeight) { 
alert(" Whether the "); 


Related articles: