Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the effect of rogue advertisement by JavaScript

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor will share with you the relevant knowledge about how JavaScript achieves the effect of rogue ads. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

When we browse the web, we often encounter all kinds of junk pop-up windows, when you turn it off, it pops up again after a period of time, which is very annoying. This kind of rogue pop-up window can be realized through JavaScript's setTimeout () method.

# ad {

Width: 400px

Height: 300px

Display: none

Background-color: # ddd

Position: fixed

Right: 0

Bottom: 0

}

# close {

Float: right

Width: 24px

Height: 24px

Line-height: 24px

Text-align: center

Cursor: pointer

Color: # fff

}

X

ten

Automatically turn off advertising after s

/ / get the object

Function get (id) {

Return document.getElementById (id)

}

/ / call the function to get the object

Var oAd = get ('ad')

Var oTime = get ('time')

Var oClose = get ('close')

ShowAd ()

/ / encapsulated function pop-up window advertisement

/ / Analysis: there are two ways to turn off the countdown 1. The end of the advertisement; 2. Click close

Function showAd () {

SetTimeout (function () {

/ / display pop-up ads

OAd.style.display = 'block'

/ / set a countdown

Var t = setInterval (function () {

/ / if the countdown ends and the pop-up advertisement is closed

OTime [XSS _ clean]--

/ / determine whether the countdown is over

If (oTime [XSS _ clean] < 0) {

/ / close the pop-up window

OAd.style.display = 'none'

/ / clear the countdown

ClearInterval (t)

/ / after the advertisement is closed, it will be 10s next time.

OTime [XSS _ clean] = 10

/ / A small advertisement pops up after 3 seconds

ShowAd ()

}

}, 1000)

/ / Click X to close

OClose.onclick = function () {

/ / close pop-up ads

OAd.style.display = 'none'

/ / clear timer

ClearInterval (t)

/ / after the advertisement is closed, it will be 10s next time.

OTime [XSS _ clean] = 10

ShowAd ()

}

}, 3000)

}

These are all the contents of the article "how to achieve the effect of rogue ads in JavaScript". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 255

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report