Really, the best thing you can do is to have good, updated antivirus, and keep your computer and web browsers updated. A lot of infections come in from ads running surreptitious malware that browsers don't always catch. They either target a vulnerable operating operating system (yes, mac people, you get them too!) file or system or a weakness in the browser to run.
Having all three maximizes the chance it gets stopped before something bad happens (as in your recent case) or gets noticed and shut down as soon as possible.