As you wrote your code, it does not work onload, it just works when the parser hits it. Since you wrote getLocation(), and not only getLocation, it performs this function.
, , window.onload=getLocation;. , ( /), , - :
window.addEventListener('load', getLocation);
, IE8. IE8, addEventListener(), , attachEvent():
if (window.addEventListener) {
window.addEventListener('load', getLocation);
} else if (window.attachEvent) {
window.attachEvent('onload', getLocation);
} else {
window.onload = getLocation;
}