Link to home
Start Free TrialLog in
Avatar of bigoldbird
bigoldbird

asked on

Go to anchor in parent frame when iframe contents change

Sorry, this should be a simple one but I have brain fog.

I have an iframe which contains a list (which may be long) and links to a specification page from that list. (I have no coding access to these pages)

When someone moves from the list to the specification page I just want to move to a named anchor at the top of the parent page (otherwise the middle of the page may be displayed and the user will have to scroll to see top of the specification) .... sounds easy!
Avatar of DennisParaguay
DennisParaguay
Flag of Paraguay image

Make your links look like this:

************************************
<A HREF="url_of_the_other_website" onClick="parent.location.href = 'url_of_the_parent_website#name_of_the_anchor';">Linktext</A>
************************************


I hope I could help you!

-Dennis
Avatar of bigoldbird
bigoldbird

ASKER

I wish it were that easy Dennis ... I have no coding access at all to the page in the iframe, so can't do anything with the links.
This is obviously more tricky than I thought!!!
Hi Big Old Bird!

Put this in the header of your parent page:

************************************
<script>
function goToAnchor(site)
{
     var anchor;
     if (site == 'url_of_the_1st_site') anchor = 'name_of_the_1st_anchor';
     if (site == 'url_of_the_2nd_site') anchor = 'name_of_the_2nd_anchor';
     self.location.href = ('#' + anchor);
}
</script>
************************************

and make your IFRAME tag look like this:

************************************
<iframe name="iframe" src="url_of_the_iframe_page" onLoad="goToAnchor(document.iframe.document.location);">
************************************


I hope this may help!

-Dennis
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area:
RECOMMENDATION:

 - [PAQ No Refund]

Please leave any comments here within the next seven days.
*******************************************************
******PLEASE DO NOT ACCEPT THIS COMMENT AS ANSWER******
*******************************************************

jAy
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of SpazMODic
SpazMODic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial