我需要使用onclick事件关闭覆盖网站的colorbox iframe。我已经将代码视为parent.$.colorbox.close(); return false;
,但是当我像这样使用它时,它对我不起作用:<a onclick="parent.$.colorbox.close(); return false;">close</a>
。我认为这是因为我没有使用标准的颜色框脚本来调用iframe。我对它进行了修改,以便从html锚标记中获取高度和宽度:
MY COLORBOX SCRIPT:
$.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"});
});
});
关闭此iframe需要用什么来点击?
答案 0 :(得分:7)
而不是:
parent.$.colorbox.close(); return false;
使用此:
parent.jQuery.colorbox.close(); return false;
你正在调用noConflict,它将jQuery与$ alias分开。因此,你的iframe无法通过$别名访问jQuery。
答案 1 :(得分:0)
您可以执行<a onclick="$.colorbox.close(); return false;">close</a>
,也可以执行$("#idOfCloseLink").click( function() { $.colorbox.close() });