Reputation: 5674
Obviously a lot of advertising people use document.write() for to insert additional scripts into a page.
For example:
var url = 'http://ads.com/buyme?rand=' + Math.random()
document.write('<script src="'+ url +'"></scr'+'ipt>')
What's the advantage of using these technique?
Why not writing <script src="'http://ads.com/buymev?rand=123"></script>
into the HTML as usual?
Or using document.createElement('script')?
What's the special benefit of using document.write() when I want to show someone advertising?
Upvotes: 1
Views: 79
Reputation: 6803
document.write can append arbitrary, even partial, incomplete and malformed HTML into document. It is very fast, because the browser doesn’t have to modify an existing DOM structure.
A great link http://javascript.info/tutorial/document-write
Upvotes: 4