Testing if the object exists before use it

It's necessary to make the code compatible with IE8 and IE9.