Javascript 如何自动关闭fancybox/lightbox/。。。x秒后弹出?
我有一个测试网站(index.html),它打开一个弹出窗口(popup.html),三秒钟后关闭。下面是index.html的标题:Javascript 如何自动关闭fancybox/lightbox/。。。x秒后弹出?,javascript,jquery,popup,fancybox,lightbox,Javascript,Jquery,Popup,Fancybox,Lightbox,我有一个测试网站(index.html),它打开一个弹出窗口(popup.html),三秒钟后关闭。下面是index.html的标题: <script language="javascript" type="text/javascript"> function popup(url) { newwindow=window.open(url,'name','height=70,width=300'); if (window.focus) {newwindow.focus(
<script language="javascript" type="text/javascript">
function popup(url) {
newwindow=window.open(url,'name','height=70,width=300');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
<a href="#" onClick="return popup('popup.html')">Open in pop-up</a>
功能弹出窗口(url){
newwindow=window.open(url,'name','height=70,width=300');
if(window.focus){newwindow.focus()}
返回false;
}
以下是index.html的正文:
<script language="javascript" type="text/javascript">
function popup(url) {
newwindow=window.open(url,'name','height=70,width=300');
if (window.focus) {newwindow.focus()}
return false;
}
</script>
<a href="#" onClick="return popup('popup.html')">Open in pop-up</a>
下面是popup.html的标题:
<script>
var howLong = 3000;
t = null;
function closeMe(){
t = setTimeout("self.close()",howLong);
}
</script>
<body onLoad="closeMe();self.focus()">
<p>Closing in 3 seconds</p>
</body>
var howLong=3000;
t=零;
函数closeMe(){
t=setTimeout(“self.close()”,howLong);
}
以下是popup.html的正文:
<script>
var howLong = 3000;
t = null;
function closeMe(){
t = setTimeout("self.close()",howLong);
}
</script>
<body onLoad="closeMe();self.focus()">
<p>Closing in 3 seconds</p>
</body>
3秒后关闭
我想用linghtbox/fancybox/which显示弹出窗口。。。然后在3秒钟后再次将其关闭。我如何才能做到这一点?我尝试了各种各样的方法,但都没有效果。实现这一点最简单的方法是什么
提前谢谢 您可以使用Fancybox(或)打开外部html
文档,几秒钟后将其关闭
对于fancyboxv1.3.x,您的html应该如下所示:
<a href="page.html" class="fancybox">open fancybox and close it automatically after 3 seconds</a>
对于fancyboxv2.x,html(注意类
):
onComplete或afterLoad对我不起作用,所以我在父页面上添加了以下代码
window.closeFancyBox = function () {
$.fancybox.close();
};
从弹出页面,我在下面的代码中调用
$(窗口).load(函数(){
setTimeout(函数(){window.parent.closeFancyBox();},3000);//3000=3秒
});代码>创建一个函数来关闭所有fancybox后加载,并为该函数设置超时
$(document).ready(function () {
closefancybox();
});
function closefancybox() {
$.fancybox({
afterLoad: function () {$.fancybox.close();}
});
setTimeout(function () { closefancybox(); }, <time_inter>);
}
$(文档).ready(函数(){
closefancybox();
});
函数closefancybox(){
$.fancybox({
后加载:函数(){$.fancybox.close();}
});
setTimeout(函数(){closefancybox();},);
}
Fancybox和其他灯箱有一个在打开时调用的回调函数,以及一个用于关闭它的公共方法,您是否尝试过在回调函数中触发close方法(超时)?检查。$。fancybox.close();使用setTimeout应该足够了。