okel okel - 10 months ago 48
Javascript Question

Trigger an ad for the first click on ANY part of the website

There are some websites where no matter where I click (background, random words, existing links, anything) an ad pops up. For example: first time I click Contact I get the Spam, but if I click Contact again I will actually go to "/contact" section.

I wonder how is this possible and how it is made.

Answer Source

Like this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
i = 0;


  if (i == 0) {
    //insert code to display ad here
    alert('spam here');

<div>blah blah blah</div>
<a href = "//stackoverflow.com">link here</a>

After the first click, i is no longer = 0, therefore the default action of body elements is restored.