On my current project we had requirement to provide mechanism for include foreign content in web page (it can be page from same domain or page from foreign domain) for mobile devices. We already had solution for desktop browser and only we should to port it for mobile. For this purpose for the desktop browser we used iframes and we wanted to do same for mobile. Here stuff have become a little bit tricky.
During developing web page for mobile device we noticed a problem with using of iframe. The complete content of iframe is loaded into page and there is no possibility to use scrolling functionality of iframe.
Loading of iframe into current page we did not see as a problem, actually we wanted that behavior but we still had a problem with scrolling. We wanted to scroll to the top of iframe in case of activating link inside of frame.
To resolve this problem, we have created a javascript function for scrolling page content to the top of iframe in the case when the top of iframe is not visible on the screen. There is simple javascript function which we used:
And we called this function on load event of iframe.
During developing web page for mobile device we noticed a problem with using of iframe. The complete content of iframe is loaded into page and there is no possibility to use scrolling functionality of iframe.
Loading of iframe into current page we did not see as a problem, actually we wanted that behavior but we still had a problem with scrolling. We wanted to scroll to the top of iframe in case of activating link inside of frame.
To resolve this problem, we have created a javascript function for scrolling page content to the top of iframe in the case when the top of iframe is not visible on the screen. There is simple javascript function which we used:
function scrollIFrame(iframe) {
var windowY = window.pageYOffset;
var frameY = iframe.offsetTop;
if (windowY > frameY) {
// Scroll to top of frame
window.scrollTo(0, frameY);
}
}
Comments
Post a Comment