With jQuery, you need to use .contents() to access what is inside the iframe. You also need to use a window load event or an iframe document ready event.
$(window).load(function () { var $contents = $('#frame').contents(); $contents.scrollTop($contents.height()); });
Demo: http://jsbin.com/ujuci5/2
I would recommend reverting to the div structure you were talking about, as this is similar to what you are trying to do, does not require an iframe. You will find that there is much less headache for working with divs than iframes.
$(function () { var $mydiv = $('#mydiv'); $mydiv.scrollTop($mydiv.height()); });
Demo: http://jsbin.com/ujusa4/2
how can I start the scroll function, like 3 seconds after the page loads?
Use setTimeout .
$(window).load(function () { setTimeout(function () { var $contents = $('#frame').contents(); $contents.scrollTop($contents.height()); }, 3000);
source share