From Affiliate Wiki
Contextual advertising works by inserting a snippet of javascript on your page. Robots will scour your page to determine the context of your page and then display relevant advertisments.
A classic example is Google Adsense, however as the web and affiliate marketing evolves there are many other solutions which I hope will be added to this Wiki article.