This article uses the example code to share with you the javascript pop-up advertisement function. The code is easy to understand and can be used for reference, for more information, see this article. We will share with you the example code to use javascript to implement the pop-up advertisement function. The code is simple and easy to understand. It is of reference value.
If you don't talk much about it, paste the Code directly. The specific code is as follows:
Var I = 0; // The number of record times var timer; // timer id // set the pop-up advertisement onload = function () {// display the ad timer once every four seconds = setInterval (showAd, 4000);} // function showAd () {I ++; // increase the number of times displayed by 1 // if I is equal to 3, clear the timer set by setInterval if (I = 3) {clearInterval (timer);} // 1. get var pObj = document. getElementById ("ad"); // 2. Modify the advertisement style pObj. style. display = "block"; // after two seconds, hide setTimeout (hiddAd, 2000);} // hide the advertisement function hiddAd () {var pObj = document. getElementById ("ad"); pObj. style. display = "none ";}