Topic: document.write == "evil" (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31454" title="Pages that link to Topic: document.write == &amp;quot;evil&amp;quot; (Page 1 of 1)" rel="nofollow" >Topic: document.write == &quot;evil&quot; <span class="small">(Page 1 of 1)</span>\

 
Maskkkk
Paranoid (IV) Inmate

From: Johnstown, PA
Insane since: Mar 2002

posted 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?



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted 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.

I've not tried to collect stats or anything but at first glance the use cases are:

  • Google analytics and other stats/tracking tools
  • building SCRIPT tags pointing to affiliate/ads programs
  • building IFRAMEs with ads
  • building OBJECTs with ads in Flash
  • building NOSCRIPT tags!!!
  • stupid calendar widgets
  • adding a A tag with a mailto: address




So far I don't feel like I'm missing much.




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 = '';
        }
    }
    
})();



Maskkkk
Paranoid (IV) Inmate

From: Johnstown, PA
Insane since: Mar 2002

posted posted 11-05-2009 18:13

Yeah I can't argue with that, but I think it depends on how you use it.

If it's in scattered snippets throughout a large page; wouldn't it be easier to read if using an onload or jQuery's $(document).ready(function {}); and then use dom functions that get id's and add nodes to them?

If you're script is being planned to be used someone else's page, like you're examples above it seems to make more sense.



- AIM: MASKKKK

01001101011000010111001101101011011010110110101101101011

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted 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.



(Edited by poi on 11-06-2009 10:24)

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

posted posted 05-31-2011 11:04
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu