我有一個測試網站(index.html),打開一個彈出窗口(popup.html),並在三秒鐘後關閉它。下面是index.html的頭:如何在x秒後自動關閉fancybox/lightbox/... popup?
<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>
這裏的index.html的身體:
<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>
這裏的彈出的身體.html:
<body onLoad="closeMe();self.focus()">
<p>Closing in 3 seconds</p>
</body>
我想使用linghtbox/fancybox /任何...顯示該彈出窗口,並在3秒後再次關閉它。我該怎麼做?我嘗試了各種各樣的東西,沒有任何工作。實現這個最簡單的方法是什麼?
在此先感謝!
的fancybox等燈箱有一個被稱爲開放的回調函數,以及一個公共的方法來關閉它,你嘗試過觸發回調函數內關閉方法(帶超時)? – mariogl 2012-02-25 12:17:02
檢查[documentation](http://fancybox.net/api)。 $ .fancybox.close();與setTimeout應該足夠你。 – 2012-02-25 12:40:10