For targeted ads like this there needs to be certain things in play, either you are allowing cookies on that site and also to have allowed third party cookies, this would allow the information from one site to be passed to the other. In your browser you can block third party cookies.
The other area where this could come in is the free toolbar scenario purporting help you do something better/quicker/(insert gimmick of your choice), etc. etc. These in a great many of these toolbars also gather marketing information that can be used for targeted ads.
Whilst this is a privacy issue, it is no less a pain in the a** and there are some things you can do for yourself:
1. Block third party cookies as I mentioned.
2. Don't allow toolbars to be installed unless you know what it is and agree as a lot of free software comes with a toolbar, which is usually opt-out (you need to say you don't want it).
3. Use an ad blocker, firefox 3.6 has add-ons for many security and privacy options; like AdBlock Plus and NoScript, etc.