Let me use a example of how we combat infections over where i work.
we mostly begin with analyzing, so lets say we found the bk-coretag.js virus, which is classified as an adware or malware virus... an innocent little bugger that annoys mroe then it does harm (if lucky!).
note that these virusses mostly appear through the installation of programs (i.e. when you install a program like CCleaner, it will ask you to "install this totally not obvious crappy adware tool you will never use", its easy to miss that, and click yes too hasty, BAM! you're infected).
these are common, you can remove them by running a virus scan (i prefer Malwarebytes for this task, since its powerfull and trusted: http://www.malwarebytes.org )
after you scanned, remove the program you think its attached to, since it has to come from somewhere (the indentifying is the tricky part).
after that, go to your browser, and reset all the setting for search engines and such, then restart your pc.
if it still occurs, you may have remoed the wrong program, so keep on digging till this works.
how to prevent? simple, when installing, read everything carefully, and WATCH WHAT YOU INSTALL, when installing random programs from the net, search around on google if theyre not "malwareliscious", and always keep your anti-virus up to date, and always a copy of malwarebytes on your PC, which runs nicly next to most anti virusses.