萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> JavaScript自動彈出窗口並自動關閉窗口代碼

JavaScript自動彈出窗口並自動關閉窗口代碼

 <HTML>

<HEAD> <TITLE>自動離開的窗口</TITLE> <SCRIPT> <!-- var flyingwin var popupwidth=200 var popupheight=150 var marginright var windowcenter var i_top=200 var i_left=-popupwidth-50 var step=40 var timer var waitingtime=5000 var pause=20 function showWindow() { flyingwin = window.open("", "flyingwin", "toolbar=no,width="+popupwidth+",height="+popupheight+",top=100,left="+(-popupwidth)+""); flyingwin.document.open(); flyingwin.document.write("<html><title>自動離開的窗口</title><body><p align=center>請不要關閉,馬上就離開:(</body></html>"); flyingwin.document.close();   if (document.all) { marginright = screen.width+50 } if (document.layers) { marginright = screen.width+50 } windowcenter=Math.floor(marginright/2)-Math.floor(popupwidth/2) movewindow()   } function movewindow() { if (i_left<=windowcenter) { flyingwin.moveTo(i_left,i_top) i_left+=step timer= setTimeout("movewindow()",pause) } else { clearTimeout(timer) timer= setTimeout("movewindow2()",waitingtime) } } function movewindow2() { if (i_left<=marginright) { flyingwin.moveTo(i_left,i_top) i_left+=step timer= setTimeout("movewindow2()",pause) } else { clearTimeout(timer) flyingwin.close() } } // --> </SCRIPT> </HEAD> <BODY onload=showWindow()> </BODY> </HTML></td>  </tr> </table>
copyright © 萬盛學電腦網 all rights reserved