Javascript 如何使用链接关闭 Fancybox
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6951653/
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
How to Close Fancybox with a Link
提问by L84
I need the ability for Fancybox to be closed when a user clicks a link inside the fancybox.
当用户单击fancybox 内的链接时,我需要能够关闭Fancybox。
I have tried:href="javascript:$j.fn.fancybox.close();"
(note I am using jQuery with no conflict hence the $j) `
我试过:(href="javascript:$j.fn.fancybox.close();"
注意我使用 jQuery 没有冲突,因此 $j)`
When I try it it does not work and I get an error in Firebug that says $j.fn.fancybox.close is not a function.
当我尝试它时它不起作用,我在 Firebug 中收到一个错误,说 $j.fn.fancybox.close is not a function.
Note: I am using Fancybox version 1.3.4
注意:我使用的是 Fancybox 版本 1.3.4
Here is the script of the Fancybox:
这是 Fancybox 的脚本:
<script type="text/javascript" >
var $j = jQuery.noConflict();
$j(document).ready(function(){
$j("#start").fancybox({
'padding' : 0
});
</script>
HTML Code for Fancybox:
Fancybox 的 HTML 代码:
<div class="hide">
<img src="/Images/skin/spacer1x1.png" onload="$j('#start').trigger('click');" />
<a href="#welcome" id="start"></a>
<img style="width:700px; height:600px;" id="welcome" usemap="#Map" alt="PLEASE VIEW PAGE WITH IMAGES ON" src="/Images/start/start.png" />
<map id="Map" name="Map">
<area alt="See Message Examples" href="/artistphotos/" coords="29,431,301,465" shape="rect" />
<area alt="Enter Site" href="javascript:$j.fn.fancybox.close();" coords="436,433,567,464" shape="rect" />
</map>
</div>
Any ideas how to get this to work properly?
任何想法如何让它正常工作?
回答by Matt Huggins
Try calling $j.fancybox.close();
rather than $j.fn.fancybox.close();
尝试打电话$j.fancybox.close();
而不是$j.fn.fancybox.close();
回答by Pathik Gandhi
<a href="javascript:void(0);" onclick="$.fancybox.close();">Close</a>
回答by vikas
<a href="" onclick="window.parent.parent.location.reload();">Close this</a>
回答by Dimger
Check this out.
看一下这个。
How to open links from inframe outside of it?
Seems like the target="_top"
does the job!
似乎target="_top"
可以完成工作!