It is very simple, but your popup will be blocked by popup blockers. You need some more creativity to get past them.
As winster said it's a simple javascript code But some browsers have popup blocker and people install plugins to stop popups. So you have a 1-10% chance of getting an ad in a popup that's viewed.