Files
doc/static/ad-1.html
2024-01-21 14:54:25 +08:00

89 lines
2.2 KiB
HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>广告页面</title>
<style>
/* 让页面内容充满整个视口 */
html, body {
height: 100%;
margin: 10px;
padding: 10px;
}
/* 居中显示内容 */
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
/* 使图片适应手机屏幕 */
img {
max-width: 100%;
height: auto;
}
/* 页脚样式 */
footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: #f0f0f0;
text-align: center;
padding: 5px 0;
}
</style>
</head>
<body>
<h1>是兄弟就找我,无兄弟不传奇!</h1>
<a href="?hinas" onclick="trackVisit()">
<img id="adImage" src="ad.jpg" alt="广告图片">
</a>
<footer>
<p>点击链接访问次数: <span id="visitCount">加载中...</span></p>
</footer>
<script>
// 获取并显示访问次数
function getVisitCount() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
document.getElementById('visitCount').innerText = xhr.responseText;
} else {
console.error('获取访问次数失败');
}
}
};
xhr.open('GET', 'ad_get_visit_count.php', true);
xhr.send();
}
// 点击图片时触发的函数,用于向后端发送访问计数请求
function trackVisit() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'ad_visit.php', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
getVisitCount(); // 更新访问次数显示
}
};
xhr.send();
// 更新图片的点击链接,可以将其指向实际的广告目标链接
document.getElementById('adImage').parentNode.href = "https://www.521f.com";
}
// 页面加载完成后获取并显示访问次数
window.onload = function() {
getVisitCount();
};
</script>
</body>
</html>