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

左心房为你撑大大i 提交于 2019-12-18 12:09:52

问题


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.


回答1:


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!




回答2:


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>



回答3:


no need to close fancy box just use

function name(){
    self.parent.location.href='pageg.php';
}


来源:https://stackoverflow.com/questions/3660710/fancybox-close-from-within-iframe-and-take-parent-page-to-the-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!