3

No matter what I do, the iframe will not auto scroll to bottom. I can't get scrollTo() to do anything to the iframe. I've checked a lot of other pages on Stack Overflow dealing with similar problems. None of their solutions have worked for me. It may well be the case that I'm simply not implementing them correctly.

Scrolling an iframe with javascript? The working example given in the above post does not in fact work for me. No matter what numbers I input into the scrollTo() method in the example nothing changes.

<!DOCTYPE html>
<html>
<body>

<div id="divy">
<iframe id='cat' src='test.html'></iframe>
</div>
<script>
console.log(document.getElementById('cat'));
 document.getElementById("cat").onload = function () {     this.contentWindow.scrollTo(0, 200) }; 
conslole.log( document.getElementById("cat").onload = function () {     this.contentWindow.scrollTo(0, 200)) }; 
    //setInterval(function(){  document.getElementById("divy").innerHTML="    <iframe src='test.html'></iframe>"; }, 3000);
</script>
<body>
</html>

Edit: I still don't know why the code in the working example on the other post doesn't work for me. Someone mentioned in the comments to that post that it didn't work for them either.

DRosenfeld
  • 115
  • 1
  • 9
cyclingLinguist
  • 334
  • 1
  • 5
  • 16

1 Answers1

1

My first two problems were that I don't know how to use the console log, and I had a typo. But I believe my main problem was I simply never entered a big enough value to see the scroll bar move and so thought it wasn't working. For the size of file I was loading 150 pixels was way too small. The code below works for me.

<!DOCTYPE html>
<html>
<body>

<div id="divy">
<iframe id='cat' src='test.html'></iframe>
</div>
<script>
console.log(document.getElementById('cat'));
 document.getElementById("cat").onload = function () {     this.contentWindow.scrollTo(0, 1000000) }; 

    //setInterval(function(){  document.getElementById("divy").innerHTML="    <iframe src='test.html'></iframe>"; }, 3000);
</script>
<body>
</html>
cyclingLinguist
  • 334
  • 1
  • 5
  • 16