Changed to prevent a cross-domain error, and to use window.addEventListener instead of window.onload.