One of the more notorious problems you might run into when using a computer is a browser hijacking attack, where stumbling upon a maliciously crafted Web site will result in an alert being repeatedly displayed, regardless of how many times you try to close it. While you might resort to force-quitting Safari to overcome this problem, with Apple’s “Resume” feature in OS X, when you re-launch the browser your Web pages will load again, resulting in the same frustrating behavior.
The classic approach to fixing this issue is to remove the saved window state of Safari, which can be done by manually trashing the saved application state folder for Safari from your user library, or by launching Safari with the Shift key held down. The problem with this is that the rest of your workflow will be closed, which can be frustrating if you had many windows and tabs open. Granted you can use options in the History menu to re-open windows from the last session, but this may open the malicious Web page and have you back where you started.
Until recently, there has not been much anyone could do to avoid these Web-based attacks, and since they cannot do much harm besides being annoying, there has been some level of resignation to their existence and recommendation to use good computing practices. These include avoiding clicking unsolicited e-mail links, popup ads, and accepting other obvious spam offerings.
As of this writing, the latest version of Safari is version 9.0, which is available as a public beta version for testing. This can be obtained by enabling pre-release software in the App Store system preferences, and then checking for updates in the App Store. Overall, simply keeping Safari and OS X up to date should make these options available to you.
If you care to test your current browser, clicking the following button will load two alerts from this page, the second of which will have the checkbox to prevent additional alerts if your version of Safari supports this feature. If not, then consider looking into updating Safari.