Although this doesn't happen very often, on occasion, whenever I visit a new website when looking for information, it turns out to be one of those malevolent ones that attempts to open up several pop-ups and redirect you to who-knows where. Whenever this happens, I usually close the browser immediately because I don't really know what these kinds of sites are doing when you visit them. I don't know much about internet security, so I don't really know the extent of what these websites are capable of doing when you simply visit them in the browser. I imagine that they probably have some kind of malicious JavaScript on the page that the browser attempts to run, but once again, I don't really understand what it's capable of.
For example, is it possible that I have a keylogger on my system now? Did it plant some kind of cookie in my browser that will try to extract information from other sites I visit? Am I part of a botnet now? I understand that these are extreme examples, but I just really don't understand the extent of what these kinds of websites can do by simply visiting them.
Additionally, do you have any advice or sequence of actions I should take whenever I do accidentally stumble into one of these sites?