0

AdSense and similar websites generates their ads on our websites by simply adding something like <script src="//example.com/ads/generateads.js"></script>. They are not having any html element with this link. When we visit on the link with script we can download their big Javascript file. I want to know how this Javascript file generates the advertisements on our website from their server. Please help me to generate such Javascript file.

dnbl
  • 15
  • 3

2 Answers2

1

Like any included script file, their javascript files can change the DOM, which means they can insert and change elements.

An example of such a file might be:

els = document.getElementsByTagName('div')
for (var key in els) {
    els[key].innerHTML += "Example"
}

You shouldn't use that (for your own sanity), but that would append "Example" to each div.

The method differs, but an example would be are injecting iframes where wanted:

ifr = document.createElement('iframe')
ifr.src = "http://www.howmanypeopleareinspacerightnow.com"
document.body.appendChild(ifr)

or injecting gifs or injecting flash objects.

humanoid
  • 240
  • 2
  • 11
0

This is also smiler question How do I generate Ad blocks with Javascript and PHP for my own Ad Network [closed]. But this answer is not much clear to me.

Community
  • 1
  • 1
dnbl
  • 15
  • 3