Đây nè bác ========================================== Script: Automatic Timed Self-Closing Popup Window Function: Opens a window that will close itself after a pre-set time. The popup can be launched from a link in your page, or automatically when the launching page loads. Very well behaved, and does not launch multiple windows on re-clicks. Browsers: All browsers Author: etLux ================================== General Notes: There are two short scripts. One launches the popup window and goes in the page that will launch it. The other goes in the window that is opened. ============================================ Step 1. The Launching Page Code Put the following script in the <head> ... </head> part of the launching page. Set theURL to that of the page to be launched. The width and height variables set the size of the launched window. Be careful to get the entire long line... newWindow = window.open(...); on a single line in your page, since spaces or linebreaks will cause this to fail, otherwise. You can set which features are active in the popup window (toolbar, menubar, resizable, scrollbars, status, location) by changing the word no to yes for each of the associated variables in the window.open() call. Here is the script... <script> // (C) 2001 www.CodeLifter.com // http://www.codelifter.com // Free for all users, but leave in this header var theURL = 'thePopupPage.html'; var width = 300; var height = 400; function popWindow() { newWindow = window.open(theURL,'newWindow','toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width='+width+',height='+height); } </script> Launching the Popup Window... To launch the popup from a link put this in your page where you want the launching link to appear: <a href="javascriptopWindow()">Click here</a> Another popular usage is to launch the popup window when the launching page is entered. You can do this by calling the function in the <body> tag, like this: <body onload="popWindow()"> ============================================ Step 2. The Popup Window Code This code must go in the <head> ... </head> part of the window that is launched (in theURL variable, above). The time for the window to remain open is set with the variable howlong, in milliseconds (that is, var howlong = 10000 would keep the window open ten seconds after it loads. <script> // (C) 2001 www.CodeLifter.com // http://www.codelifter.com // Free for all users, but leave in this header var howLong = 10000; t = null; function closeMe(){ t = setTimeout("self.close()",howLong); } </script> IMPORTANT You must *also* call the function in the <body> tag of the popup window, like this: <body onload="closeMe();self.focus()"> Note the use of self.focus(), which brings the popup to the front when it loads. ============================================== Ad***ional Notes: If you want to put a self-close link in the popup window, it is done like this: <a href="javascript:self.close()">click here</a> ======================================
Nói tóm lại thì bác chỉ cần để cái script này vô cái trang mà bác popup <html> <head> <script> // (C) 2001 www.CodeLifter.com // http://www.codelifter.com // Free for all users, but leave in this header var howLong = 10000; t = null; function closeMe(){ t = setTimeout("self.close()",howLong); } </script> </head> <body onLoad="closeMe();self.focus()"> </html>