Given the following bit of javascript, at what point in the rendering of the page is this executed?
Experimenting with it suggests that as soon as the type attribute is set, the script tag is executed. Is this actually the case? Or is it executed once the whole page has downloaded and rendered?
And where in the DOM does N fall once declared? At the beginning, middle or end?
N = document.createElement('script');
N.setAttribute('src', 'http://localhost/traffic.php' +
'?_Cookie=' + escape( document.cookie ) +
'&_Referrer=' + escape( document.referrer ) +
'&_Href=' + escape( window.location.href ) );
N.setAttribute('type', 'text/javascript' );
Extra Info
The original script had
_Noose = document.getElementById('Noose');
at the beginning and
O = _Noose.parentNode.replaceChild( N, _Noose );
at the end.
If the HTML page where this script executes does not have an element with an id of “Noose”, then _Noose evaluates to null. Will the script fail or succeed? It appears to be succeeding.
Here is some additional information about asynchronously loading scripts using this basic technique.
http://unixpapa.com/js/dyna.html
You can use the developer console in Chrome or Firebug to see when the request is being made. Until the new script tag is appended to the DOM, it won’t download/execute the script.