that kind of infection is called a "drive by download" or "Black hole Exploit".
These types of attacks take advantage of out of date software with Vulnerabilities, Most commonly the software is 1. Java and 2. adobe reader and flash.
the best protetction is education, Fbi's Parent's Guide to Internet Safety
I would like to tell you that there is a piece of software that will prevent this, but every day hackers pump out hundreds of new viruses, and software comes out that opens new holes in our computers. (ie Researcher digs up another zero-day Java bug