2011/12/1 S.A. <[email protected]>: > Hello, > This is my second attempt at trying to post this message, hope this makes it > to the list! > Here is the problem code fragment: > frag = doc.createDocumentFragment(); > div = doc.createElement('div'); > div.innerHTML = "<script type='text/javascript'>" > + res.responseText + "</script>"; > elem = div.lastChild; > if (elem.onreadystatechange) { > elem.onreadystatechange = function () { // IE > if (this.readyState == 'complete') { loadFunc(); } > }; > } else { > elem.onload = function () { loadFunc(); }; > } > frag.appendChild( elem); > doc.getElementsByTagName( 'head')[0].appendChild(frag); > > Here is res.responseText: > function loadFunc () { > console.log( "file got loaded"); > } > > From within the debugger I can see both in Chrome and FF above script > element getting inserted at the right place, but onload event does get > fired. From debugger console, if I try to invoke loadFunc() I get > 'ReferenceError'. I tried setting the break points on DOM mutations > (DOMNodeInserted, etc) and but those don't seem to hit either.
Ok, it is inserted at the right place, but are you sure, that there will be a readstatechange event? Didn't it already fired by the time that you insert your script? Also if you ever looked up the jQuery source, you can see, that when you attach a function to the ready event, it will fire "immediately" if the page is already in a ready state. -- Poetro -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
