sydd
sydd

Reputation: 1946

link inside an iframe that refers an anchor in the parent page?

I have a HTML page with the following structure:

index.html has a menu at the top, where if the user clicks stuff its loaded into an iframe at the bottom (the iframe auto resizes with JS if the content is loaded.)

Now I want to place a "go to the top" link in some of the pages, that are in the iframe, but since the anchor is in index.html it does not work, e.g:

index.html:

    <body>
    <a name="topOfThePage"></a>
    ...
    <iframe ...

in the subpages, that get loaded into the iframe in index.html:

    <a href="#topOfThePage" >go to the top</a>

This does not seem to work, anyone knows how to do this? (without JS if possible)

Upvotes: 1

Views: 1960

Answers (1)

Niall
Niall

Reputation: 456

Try adding target="_parent" to the anchor.

Edit: This will target the parent frame, but it will use the location of the iframe's page, so the href actually needs to be e.g. index.html#topOfThePage if the iframe containing page is index.html. Obviously this will only work if the iframe content page is always going to be contained used in the same containing page - let me know if that's not the case, I'll think of something else.

Upvotes: 2

Related Questions