-1

I would like to know if it is possible to modify an object in a DOM before it has loaded completely. I'm trying to modify the following object:

(function (g) {
    var d = document, 
        i, 
        am = d.createElement('script'), 
        h = d.head || d.getElementsByTagName("head")[0],
        aex = {
            "src": "google.com",
            "type": "text/javascript",
            "async": "true",
            "data-vendor": "acs",
            "data-role": "gateway"
        };
        for (var attr in aex) { 
            am.setAttribute(attr,aex[attr]); 
        }
        h.appendChild(am);
        g['acsReady'] = function () {
            var aT = '__acsReady__', 
                args = Array.prototype.slice.call(arguments, 0),
                k = setInterval(function () {
                    if (typeof g[aT] === 'function') {
                        clearInterval(k);
                        for (i = 0; i < args.length; i++) {
                            g[aT].call(g, function(fn) { 
                                return function() { 
                                    setTimeout(fn, 1) 
                                };
                            }(args[i]));
                        }
                    }
                }, 50);
        };
})(window);

to for example change the value of the src property in the above

Craicerjack
  • 6,203
  • 2
  • 31
  • 39

1 Answers1

1

Javascript execution starts before the page is rendered the first time. The DOM Parser does notify Mutation Observers, so you can immediately strip elements or modify them as soon as they are added by the parser.

This question has an example for chrome that should get you going:

Using Mutation Observer

Community
  • 1
  • 1
Neo
  • 3,309
  • 7
  • 35
  • 44