al_9x wrote:what do you mean by throw away?
That you deregister it as soon as it's called.
al_9x wrote:since you would be registering only when the script is about to be loaded, would an earlier content registration on the doc (such a thing is unlikely, typically content registers on the target itself, but still worth understanding) be invoked first?
The invocation order should be undefined by DOM specification, but in practice Firefox calls listeners on the same target in registration order.
So yes, an early registration on the doc would be called first.
al_9x wrote:when before is invoked, will the script element already exist?
Yes.
al_9x wrote:If yes, could something be done to allow the load handler to match the target by identity rather than tagName and src?
Code: Select all
var scripts = document.getElementsByTagName("script");
var myScript = scripts[scripts.length - 1];
document.addEventListener("load", function(ev) {
if (ev.target !== myScript) return;
ev.currentTarget.removeEventListener(ev.type, arguments.callee, true);
// do your "after" stuff here
}, true);
al_9x wrote:could you not attach the load handler with a match by object identity yourself? This would make the after surrogate explicit, smaller and simpler.
Yes, that's probably a good idea, mainly because of the precedence thing (the boilerplate wouldn't be that much, as you can see above).
If done implicitly by NoScript, the event handler can probably be registered at a higher level (docShell?) and be called first in capture mode.