The reason Onan was killed was not that he spilled his semen on the ground.So this widow had lost her husband and wanted to have a child according to tradition, onan on the other hand was lustful and knew that once the widow got pregnant he would not be allowed to dryfry, so to prolong his dryfry session he resulted to pour his semen in order to ensure she would not get pregnant, thus he was taking advantage of a widow for his own sexual pleasures.