SO中文参考
首页
(current)
程序语言
c
java
python
c++
go
javascript
swift
c#
操作系统
linux
ubuntu
centos
unix
数据库
oracle
mysql
mongodb
postgresql
框架
node.js
angular
react-native
avalon
django
twisted
hadoop
.net
移动开发
android
ios
搜索
通过链接访问错误跟踪用户行为用户行为</desc> <question vote="0"> <p>在这段代码中,我尝试通过给定命令和来自互联网的示例代码使用人工智能来跟踪用户行为</p> <pre><code><!DOCTYPE html> <html> <head> <title>User Behavior Tracker</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> .visited { background-color: green !important; } /* Added !important to override Bootstrap styles */ .failed { background-color: red; } </style> </head> <body> <div class="container mt-5"> <h2 class="text-center">Link List</h2> <div class="link-list"> <a href="https://www.example1.com" target="_blank" class="btn btn-primary btn-block mb-2">Link 1</a> <a href="https://www.example2.com" target="_blank" class="btn btn-primary btn-block mb-2">Link 2</a> <a href="reward-link.html" class="btn btn-success btn-block mb-2 disabled" id="rewardLink">Reward Link</a> </div> </div> <script> const links = document.querySelectorAll('.link-list a:not(#rewardLink)'); const rewardLink = document.getElementById('rewardLink'); const visitedLinks = new Array(links.length).fill(false); // Initialize visitedLinks array links.forEach((link, index) => { link.addEventListener('click', () => { const newWindow = window.open(link.href, `linkWindow_${index}`, "width=400,height=300"); // Mark link as visited after 5 seconds const visitTimeout = setTimeout(() => { visitedLinks[index] = true; link.classList.add('visited'); checkUnlock(); }, 5000); // Close the opened window after 5 seconds setTimeout(() => { newWindow.close(); }, 5000); // Handle user moving to another tab or closing the window const handleVisibilityChange = () => { if (document.visibilityState === 'hidden') { clearTimeout(visitTimeout); link.classList.add('failed'); checkUnlock(); } }; document.addEventListener('visibilitychange', handleVisibilityChange); newWindow.onbeforeunload = () => { clearTimeout(visitTimeout); document.removeEventListener('visibilitychange', handleVisibilityChange); link.classList.add('failed'); checkUnlock(); }; }); }); function checkUnlock() { if (visitedLinks.every(visited => visited)) { rewardLink.classList.remove('disabled'); rewardLink.textContent = 'Reward Link (Unlocked)'; } } </script> </body> </html> </code></pre> <p>不工作。如果我访问链接 5 秒,它不会关闭打开的选项卡,如果访问链接 5 秒也显示红色错误,但它必须显示绿色。这段代码有什么问题请帮助我。</p> <p>愿有人帮助我建造这个。</p> </question> <answer tick="false" vote="-2"> <pre><code><!DOCTYPE html> <html> <head> <title>User Behavior Tracker</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <style> .visited { background-color: green !important; } /* Added !important to override Bootstrap styles */ .failed { background-color: red; } </style> </head> <body> <div class="container mt-5"> <h2 class="text-center">Link List</h2> <div class="link-list"> <a href="https://www.example1.com" target="_blank" class="btn btn-primary btn-block mb-2">Link 1</a> <a href="https://www.example2.com" target="_blank" class="btn btn-primary btn-block mb-2">Link 2</a> <a href="reward-link.html" class="btn btn-success btn-block mb-2 disabled" id="rewardLink">Reward Link</a> </div> </div> <script> const links = document.querySelectorAll('.link-list a:not(#rewardLink)'); const rewardLink = document.getElementById('rewardLink'); const visitedLinks = new Array(links.length).fill(false); // Initialize visitedLinks array links.forEach((link, index) => { link.addEventListener('click', () => { const newWindow = window.open(link.href, `linkWindow_${index}`, "width=400,height=300"); // Mark link as visited after 5 seconds const visitTimeout = setTimeout(() => { visitedLinks[index] = true; link.classList.add('visited'); checkUnlock(); }, 5000); // Close the opened window after 5 seconds setTimeout(() => { newWindow.close(); }, 5000); // Handle user moving to another tab or closing the window const handleVisibilityChange = () => { if (document.visibilityState === 'hidden') { clearTimeout(visitTimeout); link.classList.add('failed'); checkUnlock(); } }; document.addEventListener('visibilitychange', handleVisibilityChange); newWindow.onbeforeunload = () => { clearTimeout(visitTimeout); document.removeEventListener('visibilitychange', handleVisibilityChange); link.classList.add('failed'); checkUnlock(); }; }); }); function checkUnlock() { if (visitedLinks.every(visited => visited)) { rewardLink.classList.remove('disabled'); rewardLink.textContent = 'Reward Link (Unlocked)'; } } </script> </body> </html> </code></pre> </answer> </body></html>
问题描述
投票:0
回答:0
javascript
php
user-controls
最新问题
合并 R 中的两个列表
C# 从其他类复制<summary>
行间距
iMX8 平台上的 GStreamer Pipeline。面临“检测到丢失帧”问题
使用同步方法laravel在pivot中进行软删除
Google Sheet IMPORTXML div 阶级斗争
gridjs:如何根据行ID更改背景颜色?
我可以在循环中将变化的整数值写入列表而不覆盖以前的值吗?
如何在Maven项目中使用自动生成的代码
Google 本地服务 API + CRM - 嵌套数组(API 响应映射)
有没有更好的方法来制作这个闪屏布局?
无法将 Django 服务器连接到 Cassandra DB (AstraDB)
构成成员指针类型的`::`和`*`可以来自不同的宏扩展,还是必须以单个标记的形式出现?
String是一个类? [重复]
计算径向轮廓的最有效方法
涉及 varchar 列的 Sum 语句
列名称成为从 SSRS 导出的 CSV 中的行
IIS 10 中的 Web 应用程序始终运行不工作(Blazor Web 服务器)
Python 5-Card Draw 技术堆栈决策
通过 REGEXP 或其他方式更新 String.raw 块中的值?
© www.soinside.com 2019 - 2024. All rights reserved.