FancyBox close from within iframe and take parent page to the link
Asked Answered
L

3

23

I found applying the following function to a links onclose works to close Fancybox from within an iFrame: parent.$.fancybox.close();

I want to take this further and have the link take the parent page to a new url. I've tried the following but it doesn't work:

<a onclick="location.href='http://www.domain.com/page/';parent.$.fancybox.close();"> Close and go to page</a>

using a href doesn't work either as the onclose takes precedence.

Longfaced answered 7/9, 2010 at 16:42 Comment(0)
L
35

Very simple solution... can't believe I didn't think of this!!!

<a href="http://www.domain.com/page/" target="_parent"> Close and go to page</a>

Sometime, I swear I try to make things more difficult than they actually are!

Longfaced answered 7/9, 2010 at 19:42 Comment(1)
Man, I don't care this is just a "thank you" reply. Be well and thank you. Clean and quick solution.Harleigh
K
17

You can also do this by writing a function on the parent page:

function closeFancyboxAndRedirectToUrl(url){
    $.fancybox.close();
    window.location = url;
}

Then on the link within the iframe, you can do this:

<a onclick="parent.closeFancyboxAndRedirectToUrl('http://www.domain.com/page/');">Close and go to page</a>
Kennedy answered 22/2, 2011 at 13:7 Comment(1)
This is also quite useful if you want to use a function in the modal that calls a function in the parent to actually close it (extremely useful for showing notifications within the parent when the modal closes, e.g after submitting a form)Pegram
I
17

no need to close fancy box just use

function name(){
    self.parent.location.href='pageg.php';
}
Ineluctable answered 28/2, 2012 at 4:57 Comment(1)
I've tried all the suggestions above and only this one worked for me! Thank you!Felizio

© 2022 - 2024 — McMap. All rights reserved.