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
- 秒杀 腾讯云秒杀活动→2G 内存上海机房 VPS 年付 198 元 16全球[VPS测评]
- 活动倒计时 Virmach→$15 年的 KVM 特价促销方案即将结束 全球[VPS测评]
- 云创网络洛杉矶安畅 cn2 gia 速度及综合性能测评,200M 带宽+全球[VPS测评]
- VPSMS→67 月 512MB 内存 15GB SSD 空间 1TB 虚拟空间(主机)
- HostSolutions→€3.5 月 LXC-512MB 10G S全球[VPS测评]
- 微基主机→深港 IPLC 莞港 IPLC 等转发服务 5Mbps-20M全球[VPS测评]
- 双十二 raksmart→I3 独服仅$46 月 10G 口 不限买 1全球[VPS测评]
- $19 半年 500M 内存 15G SSD 500G 流量 1Gbps美国VPS[主机]
- dedicated 月底促销 基于 LA 的 E3-1270 服务器都具全球[VPS测评]
- Worria→$60 月-E3 1230v2 8GB 1TB 2IP 1日本VPS[主机]
- 嘟牛云双十一特惠活动 续费或新购年付及以上可享受内存翻倍 买 2 年送 全球[VPS测评]
- input 标签 type 为 number 时允许输入小数的方法全球[VPS测评]
- 便宜 VPS $3.74 月 1G 内存 20G SSD 1T 流量 1全球[VPS测评]
- 特价服务器 80host 香港 CN2 线路独立服务器测试数据独立服务器[U]
- 保看奈飞 $18.75 月 2 核 CPU 1.5G 内存 30G SS日本VPS[主机]
- 秒杀 腾讯云→香港 1G 内存 VPS 年付 299 元 无需备案 北京香港VPS[主机]
- STSDUST→$25 月 2 核 2GB 内存 20GB 空间 10T虚拟空间(主机)
- hostens→3 折优惠 $1.2 月 KVM 2G 内存 1 核 2全球[VPS测评]
- 哪些WordPress收费主题最靠谱?全球[VPS测评]
- WordPress博客使用php页面代码实现外链go跳转的方法全球[VPS测评]
- Vultr VPS主机取消 $3.5入门机型及新用户赠送$25全球[VPS测评]
- 50KVM 波特兰系列机型季付优惠活动全球[VPS测评]
- VPS成立BurjeelHoldings全球[VPS测评]
- 人们为啥不爱吃海底捞了?海底捞上半年亏损达2.97亿 网友神评扎心全球[VPS测评]
- 什么是Bootstrap?全球[VPS测评]
- 购买香港服务器需要做哪些准备香港VPS[主机]
- 跨境电商周报丨拼多多布局跨境电商平台;Shopify将推出新平台支持网红全球[VPS测评]
- PQhosting:香港HE/乌克兰/俄罗斯/荷兰/摩尔多瓦vps主机/香港VPS[主机]
- dogyun:2020国庆促销,7.1折优惠,多线路vps-香港CN2、日本VPS[主机]
- 青云互联:香港vps全场终身8折优惠,CN2线路,提供大带宽vps,月付香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-222514.html











