Topic: document.write == "evil" (Page 1 of 1) |
|
|---|---|
|
Paranoid (IV) Inmate From: Johnstown, PA |
posted 11-05-2009 15:06
I'm quite sure that document.write is an evil Javascript command. But I need more evidence to back this up. Does anyone else hate this command? |
|
Paranoid (IV) Inmate From: Norway |
posted 11-05-2009 16:22
Interesting timing: earlier this week I made myself a wrapper for document.write and document.writeln. See below if you're interested.
code: /**
* wrapper for document.write and document.writeln
*/
(function()
{
var _buffer = '';
var _timeout = 0;
var _emitter = window.opera?opera.postError:window.console?console.log:alert;
document.writeln=document.write=function()
{
// the replace simply adds a \n after each closing tag
_buffer += arguments.join('').replace( /(<\/[^>]+>|\/>)/g, '$1\n' );
clearTimeout( _timeout );
_timeout = setTimeout( _dump, 100 );
}
function _dump()
{
if( _buffer!=='' )
{
_emitter( 'document.write - '+ location.href +'\n \n'+ _buffer );
_buffer = '';
}
}
})(); |
|
Paranoid (IV) Inmate From: Johnstown, PA |
posted 11-05-2009 18:13
Yeah I can't argue with that, but I think it depends on how you use it. |
|
Paranoid (IV) Inmate From: Norway |
posted 11-06-2009 09:52
document.write is an antique and lightweight method. It works even before the DOM is ready. Also it has no dependencies on the user agent implementing DOM 1+ or on a JS framework. This thing works eeeeverywhere and right away ... even in antique browsers. Oh and document.write does NOT block the user agent from loading other resources. |
|
Nervous Wreck (II) Inmate From: |
posted 05-31-2011 11:04
Edit TP: spam removed
|