If you preload your images you can have an environment variable be set by the body onlad event. This variable could switch from false to true and then your function to replace the image should have this statement: