javascript - Scroll to a particular ID within an iframe while retaining parent page position -
i needed able load particular page in iframe on demand, used simple wrapper:
function updateframe(url) { frames[0].location = url; }
then asked load page particular point, non-trivial, since pages not within control , there weren't <a name>
anchors rely on. poking around showed ids used anchors.
that say, can scroll <div id = "somewhere-down-the-line">
with:
updateframe("http://host/page#somewhere-down-the-line");
except call scrolls entire viewport above <div>
goes top , in parent page above scrolls out of view.
how modify updateframe(url)
scrolls page within <iframe>
leaves rest of page is?
this hack worked me on firefox 20.0.1/windows. essentially, load page first, jump target:
function updateframe(url) { if (url.indexof('#') > -1) { mainpage = url.split('#')[0]; frames[0].location = mainpage; } frames[0].location = url; }
i able use in other browsers well. have been trying work in chrome. maybe i'll try internet explorer...
if hack ok, , you're looking cross-browser try using scrolltop
reset were.
e.g. if body scrolls
function updateframe(url) { //save var oldscroll = document.body.scrolltop; //this moves our body! frames[0].location = url; //move document.body.scrolltop = oldscroll; }
of course if doesn't scrolls entire viewport
, instead modifies parent div or something, scrolltop property on element too.
let me know if works, screws scrolling on frame, because can modify account difference between 2 scrolltop
s
Comments
Post a Comment