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
- 补货通知 搬瓦工双向 CN2 GIA 线路 46.87 美元每年补货了全球[VPS测评]
- 劳动节促销 华为云→云服务器 1 折优惠中 1 核 2G 1M 套餐年付全球[VPS测评]
- servaRICA→$7 月 4 核 6GB 内存 80GB NVMe 虚拟空间(主机)
- CentOS 网卡错误→Determining if ip addres全球[VPS测评]
- JQuery.validate 通过 class 属性批量设置 inpu全球[VPS测评]
- 补货通知 搬瓦工→CN2 GIA 线路$46.87 年机器补货了 速度上全球[VPS测评]
- RAKsmart 五月促销→圣何塞服务器低至 46 美元起 站群服务器首站群服务器[IP]
- javascript 除法结果取整的四种方法全球[VPS测评]
- 便宜 VPS $15 年 2 核 CPU 512M 内存 50G 硬盘 全球[VPS测评]
- ¥52 月 2G 内存 20G SSD 600G 流量 100Mbps 全球[VPS测评]
- STSDUST→$5.33 月 1GB 内存 20GB SSD 空间 1虚拟空间(主机)
- Navicat 导入 mysql 提示 Err 2006-MySQL s全球[VPS测评]
- 浅谈博客运营前、中、后期如何实现盈利全球[VPS测评]
- Bigconnect-€3 月 德国Hetzner 1核2G内存20G硬全球[VPS测评]
- on9host 1核心 512M内存 15G 储存 500G流量 30M全球[VPS测评]
- 30个美容院抖音唯美文案,看到就直接拿去发吧全球[VPS测评]
- 8K超高清记录中国空间站凌月:天和核心舱与问天实验舱组成“土”字结构虚拟空间(主机)
- 什么是linux面板?常见的Linux控制面板有哪些?全球[VPS测评]
- 如何更改WHMCS默认后台路径让WHMCS系统更安全全球[VPS测评]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- WordPress去掉分类链接中category目录的两种方法全球[VPS测评]
- MoonVM,香港HKT家宽VPS服务器,动态IP一键切换,1G带宽任意香港VPS[主机]
- 安国云:1核/1G/20G硬盘/1Mbp不限流量/香港cdia,月付18香港VPS[主机]
- 腾讯云海外服务器优惠活动:全球购1核2G美国云服务器低至318元/年美国VPS[主机]
- 虾皮跨境电商怎么样?虾皮跨境电商靠谱吗?全球[VPS测评]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- uuuvps:香港VPS低至97元/年,CN2+bgp网络,香港机房VP香港VPS[主机]
- 阁天互联怎么样?香港cn2云服务器 圣何塞cn2vps仅20/月香港VPS[主机]
- 六六云:1核1GB/15GB空间/1T流量/100Mbps/KVM/香港虚拟空间(主机)
- 腾讯云香港轻量应用服务器 优惠活动最低月付仅24元香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-222751.html











