Entry
How can I scroll an IFRAME up and/or down?
Feb 19th, 2001 05:53
Martin Honnen,
Here is a complete example that works with NN6, IE4+ and Opera 5:
<HTML>
<HEAD>
<TITLE>
iframe scrolling
</TITLE>
<SCRIPT>
var step = 20;
var tid;
var oldPageYOffset;
function scrollIframe () {
if (window.anIframe && window.anIframe.scrollBy) {
var ifr = window.anIframe;
ifr.oldPageYOffset = ifr.pageYOffset;
ifr.scrollBy(0, step);
if (window.opera) {
if (ifr.pageYOffset == ifr.oldPageYOffset)
step = -step;
}
else if (document.all) {
if (ifr.document.body.scrollTop <= 0 ||
ifr.document.body.scrollHeight - ifr.document.body.scrollTop
<= ifr. document.body.offsetHeight)
step = -step;
}
else if (document.getElementById) {
if (ifr.pageYOffset <= 0 ||
ifr.document.height - ifr.pageYOffset <= ifr.innerHeight)
step = -step;
}
}
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="tid = setInterval('scrollIframe()', 100)">
<IFRAME NAME="anIframe" WIDTH="780" HEIGHT="100"
SRC="whatever.html"></IFRAME>
</BODY>
</HTML>
Note that IE and NN only allow the scrolling if the IFRAME is from the
same server as the scrolling script