Good for you for reading about this first! People used to do that, but not so much these days...
Anyway go to google.com, click on "Images" on the top or left, then search for the following words...
old work electrical box
You will see there are many different types of old work boxes available. Some of the plastic kind have a tab at the end of a screw. You could always get a longer screw if necessary.
Anyway check at hardware stores and electrical supplies (where electricians shop) as well.
Then the following is how to install an old work box in drywall. For plaster and lath, just add a lot of curse words to the following
http://www.hammerzone.com/archives/elect/remodel1/lighting/track2ft/oldworkbox.htm