Add check to make sure document.body and document.head exist before call...

...ing their contain methods, see #98