通过链接访问错误跟踪用户行为用户行为</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
© www.soinside.com 2019 - 2024. All rights reserved.