hidePutCode function overwrites window.onload instead of adding to it
Opened this issue · 0 comments
photomedia commented
In this line:
The window.onload function is overwritten to hidePutCode, but this is potentially problematic if there was already other window.onload functions registered, as was the case in my repository.
The safer way is to ADD the function, rather than overwrite.
Here is how I do that:
function addWindowOnLoad(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function () {
if (oldonload) {
oldonload();
}
func();
}
}
}
addWindowOnLoad(hidePutcode);
This ensures that hidePutcode is added to any existing window.onload functions, if they are already some defined. I recommend this safer way of doing it.