0

I have an iFrame element that displays a log output file from a Python script I'm running on my website. The log file is quite long, so I'd like to have the iFrame element automatically scrolled to the bottom, that way less scrolling is initially required.

I've tried methods on the following stack exchange pages: 1) jQuery Scroll to bottom of page/iframe 2) Scroll to bottom of Div on page load (jQuery) 3) How to scroll an iframe to the bottom when page loads?

I am hoping to use jQuery to conduct this operation. I've verified that bringing in jQuery from googleapis is not the issue, as another jQuery function I've written works fine. I've been trying different combinations of code from these three sources and just can't seem to nail it down.

I've read from one source that the .contents() is required for jQuery to get the contents of an iFrame, so I've been using that. I also tried a few other methods in .scrollTop() such as just putting a large number, but nothing seems to do the trick. Any help would be appreciated, as I'm pretty new to jQuery.

I also attempted to use Javascript alone as the solution from this stackexchange link: Scrolling an iframe with JavaScript?. However, this also was not working to scroll the frame automatically.

HTML

<div class="logbox">
<iframe id="frame" scr="/logs/exampleLog.log" frameborder="2" height='100%' width='100%'></iframe>
</div>

CSS

.logbox {
  -webkit-overflow-scrolling: touch;
  align: center;
  background-color: #F5F5F5;
  max-width: 100%;
  height: 300px;
}

jQuery

<script>
  $(function(){
      $("#frame").contents().scrollTop($('#frame').contents().scrollHeight);             
  });
</script>
JChopra
  • 1
  • 1
  • 1
    Possible duplicate of [Scrolling an iframe with JavaScript?](https://stackoverflow.com/questions/1192228/scrolling-an-iframe-with-javascript) – Zak May 23 '19 at 19:05
  • I checked that out as well, but the solutions there were not working for me. I was wondering if perhaps those methods are outdated now? – JChopra May 23 '19 at 19:53

0 Answers0