Forum Moderators: open

Message Too Old, No Replies

iframe and anchors

Linking to anchors inside an iframe

         

sakram

1:52 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



Hi,

I have this page (resume.htm) displayed inside an iframe on a page (cv.shtml). There are several anchor tags inside resume.htm for in-page navigation convenience.

I need to find a way how I can link into a particular anchor tag inside resume.htm (for example: resume.htm#education) by linking into cv.shtml first, and then displaying the particular anchor on resume.htm. Any help on this matter is much appreciated! Thanks in advance!

BonRouge

2:40 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



You want links (to anchors in your resume) on the cv page?
This should do it :

Make sure your anchors have names (e.g. name="great-things-about-me").

Put this script in your head :

<script type="text/javascript">
function ifill(iframe,page) {
eval("parent."+iframe+".location='"+page+"'");
}
</script>

Give your iframe a name :

<iframe name="i" src="resume.htm" height="500px" width="100%"></iframe>

Add a link :
<a onclick="ifill('i','resume.htm#great-things-about-me')" href="#">Great things about me</a>

And er... that's it.

This worked when I tested it, so if you have any problems, let me know and I'll try to explain more clearly.

Cheers.

sakram

3:32 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



Thanks a bunch! Works like a charm! That answers one of my problems.

I have resume.htm as the source of iframe on cv.shtml. Say for example, I have index.shtml (and index.shtml doesn't have any iframes), how do I add a link in index.shtml that will take me to a particular anchor position in resume.htm (such as resume.htm#technical), but will show that in cv.shtml? I hope I was clear in explaining this as succinctly as possible!

I've got to learn javascript real soon, sigh :(.

BonRouge

3:54 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



This is where you need someone who actually knows something...(ie. not me)

As far as I know - what you want isn't possible, but I've been wrong soooo many times before...

sakram

4:01 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



Well, thanks a lot anyways, it was really nice of you to lend a helping hand! I've never used a forum before, this has been sort of a revelation for me!

BonRouge

4:03 pm on Nov 21, 2004 (gmt 0)

10+ Year Member



My pleasure ;)

kaled

12:40 am on Nov 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to use an url such as resume.htm?iframesrc%23anchorname.

You will need to add the following code to resume.htm. I would place it at the end of the HTML.

function loadIframe()
{ i.location.href = unescape(document.location.query) }

where i is the name of the iframe.

Note that '%23' is translated into '#'

Kaled.

<added>
Would it be better to use <iframe id="subframe">
and then use
var i = getElementById('subframe');
</added>