cluster1
cluster1

Reputation: 5674

What is the advantage of inserting a script-tag by using document.write() (for displaying individual advertsing)?

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

Answers (1)

Piyush.kapoor
Piyush.kapoor

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

Related Questions