Abnormal behavior of web browser in OS X
In addition to running anti-virus software, as mentioned by Steve, above, you should check and clean out your browser's cache and extensions. 

(1) Safari


  Safari --> Help --> Installed Plug-ins


Here, plug-ins called "Quicktime" and "Flash" are OK, and are not likely culprits.


  Safari --> Safari --> Preferences --> Extensions


Here, think long and hard about whether you actually need the services offered by any extension here.  If you do, check you've got the latest and disable or delete the rest.


  Safari --> Safari --> Preferences --> Advanced --> Proxies


Here, check to see if there are any proxies, which are instructions to visit some other site before going to the site you wish to visit.   Sometimes proxies are needed to get past restrictions put on you by your ISP, like the hotel you're staying at, but they're uniquely positioned to redirect you anywhere, and to pop open new web pages.  

(2) Chrome


  Chrome --> Preferences... --> Extensions


Check here for any extension you don't recognize.  Disable or delete anything you don't need.


  Chrome --> Preferences... --> Settings -- > Search


Set your search engine to something you recognize and trust.  If you're in doubt, use "Google" or "DuckDuckGo" or even "Yahoo!" and delete the rest.


  Chrome --> Preferences... --> Settings -- > Show advanced settings... --> Network


Click here to look at your proxy settings.  Unless you need a proxy because you travel a lot, or you live in a repressive country, or your computer is part of an enterprise network, you probably don't need a proxy.