I'd highly recommend the Firefox extension called
NoScript. It blocks Javascript on almost all sites until you create your own "whitelist" of sites that can use Javascript. You can also choose, through the NoScript options, to disable Flash on unapproved sites.
It may seem like a lot of work at first to approve sites one by one, but you won't get
any unexpected pop-ups (Flash or Javascript), and you can export and import your settings in case you ever have to migrate to another computer.