4 ms·
Why oh why does it use document.write? https://github.com/enyojs/enyo/blob/master/source/dom/Control.js#L293 https://github.com/enyojs/enyo/blob/master/source/
by jlongster 15y ago
Why oh why does it use document.write?
https://github.com/enyojs/enyo/blob/master/source/dom/Control.js#L293 https://github.com/enyojs/enyo/blob/master/source/dom/Contro...
- whalesalad 15y agoCan you explain why this is a bad thing?
- gryzzly 15y agohttp://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice http://stackoverflow.com/questions/802854/why-is-document-wr...
- underwater 15y agoI imagine it makes the API easier for non-JS developers. Considering its origins as a purely client-side library it does makes sense, as there would be no need to worry about moving script tags down the page to speed up execution. Technically, you could probably replace the document.write with something like: var scripts = document.getElementsByTagName('script'); var current = scripts[scripts.length - 1]; var temp = document.createElementNode('div'); temp.innerHTML = this.generateHTML(); current.parentNode.insertBefore(temp, current); I wrote a script that hijacks document.write calls a little while back (https://github.com/joshduck/Injector.js https://github.com/joshduck/Injector.js) which lets you inject arbitrary HTML into your document and then execute inline scripts (including document.write) at a later time.
- unwiredben 15y agoYou don't have to use the .write method. The way enyo 1.0 works and the way that's still supported is to use .renderInto(domNode) to replace the innerHtml of a node with the new content. This is especially useful from the console, since writes don't work there.