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
- 大流量 $25 年 2G 内存 20G SSD 5TB 流量@1Gbps全球[VPS测评]
- DogYun 月付 15 元的圣何塞双程 giavps 速度及综合性能测全球[VPS测评]
- js 动态改变文本颜色全球[VPS测评]
- 初春优惠 糖果主机→香港云服务器¥27.75 月起 虚拟主机新购最低可享香港VPS[主机]
- 去掉 power by dedecms 的两种方法全球[VPS测评]
- 微信开发→"errcode": -1000,"errmsg": "sys全球[VPS测评]
- Virmach 美国新泽西州皮斯卡特维机房 VPS 测评数据美国VPS[主机]
- Fresh Roasted Hosting→$30 月 I3-540 8全球[VPS测评]
- [黑五]CloudCone→洛杉矶按小时计费 KVM 年付 10 美元起全球[VPS测评]
- 玩具-Hostdoc→$3.68 年付 堪萨斯 VPS 1 核 256M全球[VPS测评]
- 看奈飞 99 元 月 1G 内存 10G 硬盘 1T 流量 300Mbp全球[VPS测评]
- DedeCMS 去掉后台登录页面广告的办法全球[VPS测评]
- NameCheap - 域名转入优惠 .com $4.88 年 .net全球[VPS测评]
- 优惠 CloudCone→2 美元月付起 洛杉矶 CN2 线路 按小时计全球[VPS测评]
- DMIT 洛杉矶 CN2 GIA 大带宽 VPS 促销,最高 7.5 折美国VPS[主机]
- OG协议对博客Google SEO优化有什么帮助?全球[VPS测评]
- 野草云香港CN2 VPS 云服务器年付三六折优惠,¥136.8起/年;独独立服务器[U]
- 百度搜索将打击网站搜索内容需获取权限才能查看的情况全球[VPS测评]
- Kuroit 双十一 英国VPS服务器 测试(11.11£ 年)全球[VPS测评]
- 言車新车|大阳VPS125混动踏板,长续航,代步通勤9980元起全球[VPS测评]
- 6种样式社交论坛网站HTML5模板 - Social全球[VPS测评]
- “休闲养蜂”风靡海外跨境电商追逐垂直风口全球[VPS测评]
- 极客主机,优惠8折充值返25%,香港CN2VPS,日本软银VPS,新加坡日本VPS[主机]
- 因搜包耽误员工下班,苹果将支付3050万美元赔款全球[VPS测评]
- 跨境电商平台首选香港服务器香港VPS[主机]
- 跨境贸易和跨境电商的三大区别简单分析全球[VPS测评]
- 云米科技:新春欢庆,香港云服务器/美国高防vps服务器全场八折,支持按天美国VPS[主机]
- 恒创科技:香港/美国云服务器2折起,年度特价低至13元/月,新购送京东E美国VPS[主机]
- 金斗云怎么样?香港CN2月付23元,圣何塞CN2月付22元香港VPS[主机]
- 桔子数据:香港CN2大带宽云服务器28元/月_1核/1G/10M带宽/C香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-222514.html











