Automatically Close Popup Window

What can I add to an HTML file presented in a popup window called by a script to automatically close that popup window after so many seconds? I have tried , which should work but I get error messages in Internet Explorer.


You are very close to solving your own problem. The window.close command will close the current window, while the setTimeout command executes an arbitrary piece of JavaScript code after a specified delay. This can be any bit of valid JavaScript, including function calls, multiple commands (separated by semicolons), and also the window.close command. However, what’s tripped you up is that the JavaScript you’d like to execute must be passed to the setTimeout function as a string. This means it has to be in quotes. Your code doesn’t include the quotes and so it results in a syntax error.

There are two additional items to watch out for. First, you have to use the right set of quotes. JavaScript supports both single and double quotes. Since you’re using double quotes to wrap the onLoad event handler you’ll need to use single quotes to enclose the JavaScript you want to pass to the setTimeout function. Second, just because you call the window.close function, doesn’t mean the window will actually close. In many cases, the browser will display a confirmation dialog for the user and allow him to cancel your window.close call.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a