jQuery\'s scrollTop returns null when window is an iframe. Has anyone been able to figure out how to get scrollTop of an iframe?
more info:
my script is runn
$('#myIframe').contents().scrollTop()
I found this question while trying to SET scrollTop inside an iframe... not exactly your question (you wanted to GET) but here's a solution inside iframes for people that also end up here trying to SET.
If you want to scroll to the top of the page this will NOT work inside an iframe:
$("html,body").scrollTop(0);
However, this will work:
document.getElementById("wrapper").scrollIntoView();
Or the equivilent with jQuery:
$("#wrapper")[0].scrollIntoView();
For this markup (contained inside an iframe):
<html>
<body>
<div id="wrapper">
<!-- lots of content -->
</div>
</body>
</html>
Good old javascript:
scrollTop = document.getElementById(IFRAME_ID).contentWindow.document.body.scrollTop;
or use this one
sample.showLoader = function() {
// show cursor wait
document.getElementsByTagName('body')[0].style.cursor = 'wait';
var loader = $('#statusloader');
// check if we're runnign within an iframe
var isIframe = top !== self;
if (isIframe) {
var topPos = top.pageYOffset + 300;
// show up loader in middle of the screen
loader.show().css({
top : topPos,
left : '50%'
});
} else {
// show up loader in middle of the screen
loader.show().css({
top : '50%',
left : '50%'
});
}
};