Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hidePutCode function overwrites window.onload instead of adding to it #69

Open
photomedia opened this issue Aug 20, 2022 · 0 comments
Open

Comments

@photomedia
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant