[英]How do I close colorbox iframe with javascript?
I need to close the colorbox iframe that overlays the website with an onclick event. 我需要关闭通过onclick事件覆盖网站的colorbox iframe。 I have seen the code as parent.$.colorbox.close(); return false;
我已经将代码视为parent.$.colorbox.close(); return false;
parent.$.colorbox.close(); return false;
, but it doesn't work for me when I use it like this: <a onclick="parent.$.colorbox.close(); return false;">close</a>
. ,但当我这样使用它时,它对我不起作用: <a onclick="parent.$.colorbox.close(); return false;">close</a>
。 I think that it is because I am not using a standard colorbox script to call the iframe. 我认为这是因为我没有使用标准的colorbox脚本来调用iframe。 I modified it so that I can get height and width from the html anchor tag: 我对其进行了修改,以便可以从html锚标记获取高度和宽度:
MY COLORBOX SCRIPT: 我的COLORBOX脚本:
$.noConflict();
jQuery(document).ready(function($){
$("a[rel='colorbox']").each(function(){
var getWidth = parseInt($(this).attr('width'))
var getHeight = parseInt($(this).attr('height'))
var getScroll = parseInt($(this).attr('scrolling'))
if(getScroll == 'yes') { var frameScroll = 'true'; }
if(!getWidth) { var getWidth = '720'; }
if(!getHeight) { var getHeight = '480'; }
$(this).colorbox({innerWidth:getWidth, innerHeight:getHeight, scrolling:frameScroll, iframe:true, rel:"nofollow", transition:"elastic"});
});
});
What do I need to use to close this iframe onclick? 我需要使用什么来关闭此iframe onclick?
Instead of this: 代替这个:
parent.$.colorbox.close(); return false;
Use this: 用这个:
parent.jQuery.colorbox.close(); return false;
You are calling noConflict, which divorces jQuery from the $ alias. 您正在调用noConflict,它使jQuery与$别名分离。 Therefor your iframe is not going to be able to access jQuery through that $ alias. 因此,您的iframe将无法通过该$别名访问jQuery。
您可以执行<a onclick="$.colorbox.close(); return false;">close</a>
$("#idOfCloseLink").click( function() { $.colorbox.close() });
<a onclick="$.colorbox.close(); return false;">close</a>
,也可以执行类似$("#idOfCloseLink").click( function() { $.colorbox.close() });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.