iFramed for a crime I didn't commit
February 11, 2006 9:48 AM
Subscribe
I'm trying to get iFrames, anchors and hyperlinks to play nice together.
PLEASE don't tell me not to use iFrames. It's not my decision -- the client insists.
That said, pageA.html contains a large iFrame that is reading in content from datafile.html. In datafile.html, there are anchors. Let's say there's an anchor called "anchor01".
I've been asked to create a NEW page -- pageB.html -- that links to the pageA.html -- but it needs to link to anchor01. Of course, anchor01 is not actually IN pageA.html, so when I link to pageA.html#anchor01, it doesn't work. Anchor01 is in datafile.html, but I'm hoping there's a way to link to it (without linking directly to datafile.html) THROUGH pageA.html -- since pageA is sucking in all of datafile.
I'm open to html, css, javascript and backend solutions -- the simpler the better. And, of course, this need to be x-browser.
My old friend Google is failing me. Or maybe I'm failing him.
posted by grumblebee to computers & internet (12 comments total)
I suspect the following will work, but I haven't tested it:
1. you need to scroll the frame's content. Presumably, this is, in javascriipt, something liike:
c.scrollTop = a.offsetTop, where c is the content in the iframe and a is the anchor within that content.
2. You need -- presumably -- to do that scrolling only when the full url is pagea.html#anchor1
So you need an onload javascript on pagea that looks at document.location.href and sees if ends with "#anchor1" -- in which case it needs to find the iframe (which you can presumably hardcode) and scroll it as in step 1.
The actual coding I leave to you.
posted by orthogonality at 10:27 AM on February 11, 2006