I have a page setup that is accessed through a fancybox iframe. How can a link that is inside the fancybox iframe, load in the parent window of the iframe? So if the user clicks the link, it will reload the page and load the clicked link. How do I add a target="_top" attribute to the all links?
e.g.
$("iframe").on("load", function () {
$("a").each(function() {
$(this).attr('target', '_top');
});
})
If you are using Fancybox 3, you will want this slightly altered version:
Adding this extra answer as this thread is about the only near useful thing that shows up in searches. I felt it was worth updating for the current version of Fancybox.
Assuming that in your child page you have regular links like :
You could set the attribute
onclick
to each link from within the parent page using the fancyboxafterShow
callback. Then, setparent.location.assign()
and$.fancybox.close()
as theonclick
attribute value.This is the code for your parent page :
Now, each link on the iframed page will close fancybox and load the referred URL in the parent (top) page.
NOTES :
this.href
within the.assign()
method, which corresponds tohref
value of each link.See demo : http://www.picssel.com/playground/jquery/openURLfromChildPage_13apr14.html