我正在尝试从 iframe 调用 colorbox close() 函数。这就是我所拥有的。
主页
<script>
$(document).ready(function(){
$("#click").colorbox({width:"60%",
height:"60%",
iframe:true
});
});
</script>
<a href="login.html" id="click">Click Me!</a>
登录.html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="jquery.colorbox.js"></script>
<script>
$(document).ready(function(){
setTimeout(function() {
parent.jQuery.fn.colorbox.close();
}, 3000);
});
</script>
</head><body></body>
</html>
调用 settimeout 时出现此错误。
Uncaught TypeError: Cannot read property 'fn' of undefined
我尝试遵循此线程中的答案。 how to close colorbox within iframe?
最佳答案
我们可以使用
parent.jQuery.fn.colorbox.close();
效果很好
关于jquery - 从 iframe 调用关闭 colorbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15506197/