JavaScript Change attribute HTML code before append and run

I wrote this html code:

<html xmlns="" xml:lang="en" lang="en">
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <script src="" async defer></script>

loader.js load from browser and it create script tag with createElement , then set src to alert.js, then appendChild append it to head tag. see source

No Problem. that is fine

I want change src attribute, before appendChild run!

For example, i want change alert.js to alert2.js before it load, i want hook appendChild and if src equal to alert.js, stop it and change src to alert2.js ...

I wrote this code and wrap createElement,

document.createElement = function(create) {
    return function() {
        var ret = create.apply(this, arguments);
        if (ret.tagName.toLowerCase() === "script") {
        return ret;

but this code return undefined



comments powered by Disqus