jQuery FancyBox 从 iframe 内关闭并将父页面带到链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3660710/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
FancyBox close from within iframe and take parent page to the link
提问by Mr Jonny Wood
I found applying the following function to a links onclose
works to close Fancybox from within an iFrame:
parent.$.fancybox.close();
我发现将以下函数应用于链接onclose
可以从 iFrame 中关闭 Fancybox:
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:
我想更进一步,让链接将父页面带到一个新的 url。我已经尝试了以下但它不起作用:
<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.
usinga href
也不起作用,因为onclose
优先。
回答by Mr Jonny Wood
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!
有时,我发誓我试图让事情变得比实际情况更困难!
回答by Ryan Kohn
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:
然后在 iframe 内的链接上,您可以执行以下操作:
<a onclick="parent.closeFancyboxAndRedirectToUrl('http://www.domain.com/page/');">Close and go to page</a>
回答by tarshi
no need to close fancy box just use
无需关闭花哨的盒子只需使用
function name(){
self.parent.location.href='pageg.php';
}