Wednesday, 7 August 2013

set scrollTop from an iframe to his parent

set scrollTop from an iframe to his parent

I stored the scrollbar position with scrollTop in a session during the
onclick event who's opening my iframe.

I'm trying to reset it from the iframe to the parent page using an other
onclick for closing my iframe and re-inject the scrollTop value in the
same time...

But the parent scrollbar stays at the top of the parent page when I close
the iframe.
The function I call on parent page:
function unloadScrollBars() {
store = document.body.scrollTop; // where you want scroll
window.sessionStorage['scroll'] = store;
alert(store); // just for check the value
document.documentElement.style.overflow = 'hidden'; // firefox, chrome
document.body.scroll = "no"; // ie only
}
Then the function I call in the iframe:
function reloadScrollBars() {
parent.document.documentElement.style.overflow = 'auto'; // firefox,
chrome
parent.document.body.scroll = "yes"; // ie only
parent.document.body.scrollTop = sessionStorage['scroll'];
alert(sessionStorage['scroll']); // just for recheck the value
}
May it be a syntax problem?

No comments:

Post a Comment