WordPress网站代码实现网站弹窗广告
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

平时访问网站、博客时经常可以看到,打开网页后看到弹出一个图片广告。
作为普通访客是比较反感这种广告方式的。
作为网站站长,需要通过广告来为网站运营支付主机、域名等费用。我个人非常喜欢这样的功能。
[ad]
尝试了好多种版本,但是一直未找到合适的代码。好不容易在蝈蝈要安静网站看到这个代码,就顺手扒了过来。
内容 1 JavaScript 代码 2 CSS样式代码 3 前端HTML显示代码 4 相关文章JavaScript 代码
var popup = document.getElementById('qgg_popup');var popup_box = document.querySelector('.qgg_popup_box');var popup_close = document.querySelector('.qgg_popup_close');// 窗口加载时弹出window.onload = function() { popup.style.display = "block";}// 点击窗体其他位置时关闭window.onclick = function(event) { if (event.target == popup) { popup.style.display = "none"; }}popup_box.onclick = function() { popup.style.display = "none";}// 点击关闭按钮时关闭popup_close.onclick = function() { popup.style.display = "none";}WordPress建站的小伙伴们将JS代码丢到主题的主JS文件中去即可。DUX主题用户直接丢到主题 js 文件夹下的 main.js 文件中即可。
CSS样式代码
html, body{ margin:0; height:100%; }#qgg_popup{ position: fixed; top: 0; left: 0; display: none; width: 100%; height: 100%; margin: auto; background: rgba(36, 36, 36, 0.8);}.qgg_popup_box { z-index: 10; position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 280px; height: 396px; margin: auto; text-align: center; } .qgg_popup_close{ position: relative; width: 36px; height: 36px; background: #fff; color: #999; float: right; font-size: 24px; text-align: center; border-radius: 50%; line-height: 36px; font-weight: bold;}.qgg_popup_close:hover,.qgg_popup_close:focus { color: red; cursor: pointer;}.qgg_popup_img{ position:relative; top: 36px; left: 0px; width:240px; height:360px; border-radius: 15px;}@media (max-width: 640px){ .qgg_popup_close{ display: none; }}使用 WordPress搭建网站的小伙伴将代码丢到主题的 style.css 文件中即可。
大前端的DUX 主题有点儿特殊,丢到 main.css 文件中即可。
前端HTML显示代码
<!-- 弹窗广告 --><div id="qgg_popup"> <div class="qgg_popup_box"> <span class="qgg_popup_close">×</span> <img class="qgg_popup_img" src="./1.png"> </div></div>这段代码是前端显示的 HTML ,将其丢到你想要其显示的页面中即可,比如 index.php 、single.php 文件中即可。
[WordPress]历史优惠活动内容
猜你可能想看的VPS
- 补货通知 搬瓦工→$49 年 1G 内存 1T 流量 CN2 补货了 有全球[VPS测评]
- Name.com 4 月域名促销全球[VPS测评]
- STSDUST→$5.33 月 1GB 内存 20GB SSD 空间 1虚拟空间(主机)
- Vultr 支持微信扫码充值 日本 洛杉矶 1 核 512M 内存 1G日本VPS[主机]
- Launchvps→费城 KVM 月付 2.9 美元起 500M 带宽 全球[VPS测评]
- 送美元 RackNerd 春节促销→登陆 购买最高送$188 红包 独立独立服务器[U]
- 免费换 IP LosAngelesvps→1.5G 内存套餐年付$19.全球[VPS测评]
- 便宜 $1.57 月 1 核 512M 内存 5G SSD 25Mbps全球[VPS测评]
- ThinkPHP5 提示 A non well formed numer全球[VPS测评]
- Class 'PDO' not found全球[VPS测评]
- 促销 sernethosting 全场 8 折优惠→250G 不限流量大全球[VPS测评]
- 疯狂猜成语 图猜成语两个人在说话前面有一个人在笑是什么成语?全球[VPS测评]
- 阳帝云 美国CN2 GIA高防 VPS 1g内存40G硬盘外带200G防美国VPS[主机]
- WordPress插件:Add-Document-Pages为你的网站增全球[VPS测评]
- 傲游主机洛杉矶CN2GIA VPS八折优惠 2G内存/强制三网CN2G全球[VPS测评]
- DesiVPS元旦 洛杉矶便宜VPS 1.5G内存年付仅20刀全球[VPS测评]
- 无忧云云服务器八五折,香港三网cn2折上折,最低月付48.9元香港VPS[主机]
- BuyVM → 卢森堡 DMCA友好 无限流量全球[VPS测评]
- 播放量破千万,点赞量破百万,你绝对想不到这三款多功能产品居然在TK上卖爆全球[VPS测评]
- LOCVPS:香港vps八折优惠中,双十一预热,充值充600送150,六香港VPS[主机]
- 恒创科技:香港/美国云服务器2折起,年度特价低至13元/月,新购送京东E美国VPS[主机]
- 20个温暖心灵的问题,抖音,朋友圈都可以拿去发。全球[VPS测评]
- 厘米云,江苏移动100G高防云服务器,4核4G内存20M带宽79元/月全球[VPS测评]
- cmivps:全场7折,香港不限流量VPS,Windows系统,LinuWINDOWS
- 三优云uuuvps:春节促销,香港cn2 vps低至168元/年,多款配香港VPS[主机]
- wikihost,微基主机:1核/1G/15G/100Mbps/香港vp香港VPS[主机]
- 腾讯云vps主机:288元/3年,1核/2G/50gSSD,北京/上海/美国VPS[主机]
- GreenCloudVPS:6折优惠,日本、新加坡、香港等KVM VPS日本VPS[主机]
- vpsplayer:新年活动_vps全部7.5折起_深圳BGP/美西Ce香港VPS[主机]
- 香港cn2线路服务器哪里好?香港cn2服务器推荐哪家好?香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-227110.html











