Do you like my tutorials?

Then consider supporting me on Ko-fi

Talking about Javascript.

Some days ago I showed you how to create a dynamic content animated footer ad for your site in just 9 jQuery lines.

Now it’s time to write eight more lines to add two important features:

The first, as suggested in a comment, is allowing to set a delay before the ad appears.

The second is using a cookie to let the ad appear only once in a session. This means if you refresh the page, the ad won’t appear again, until you close the browser window and open it again.

This is what we’ll get… the ad appears after three seconds, and only once in a session.

Now let’s see the new lines added:


Lines 3-6: Declaring a new jQuery function called delay, that’s just a callback after a given amount of milliseconds.

Line 8: Variable storing the number of milliseconds to wait before showing the ad

Line 9: Variable storing the path to the dynamic file

Line 10: Checking if I have a cookie called triqui_ad. The statement is true if I don’t have it.

Line 11: Creating a cookie called triqui_ad. Since there is not an expiration date, it will expire when the user will close the browser.

Line 14: The entire function explained in part 1 is executed only after the preset delay.

And that’s it… any idea for additional features?

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.