Показать сообщение отдельно
  #7 (permalink)  
Старый 19.02.2021, 15:51
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,070

выделение кликнутых ссылок
Сергей Ракипов,
кликнуть по одной из ссылок, перезагрузить пример.
<!DOCTYPE html>
<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style type="text/css">
a.visited{
    color: #000;
    text-decoration: none;
    text-decoration-line: line-through;
    cursor: no-drop;
}
    </style>
</head>
<body>
<a href="https://www.youtube.com/" title="https://www.youtube.com/" target="_blank">https://www.youtube.com/</a>
<a href="https://www.google.com/" title="https://www.google.com/" target="_blank">https://www.google.com/</a>
<script>
document.addEventListener("DOMContentLoaded", function() {
    let link = localStorage.link ? JSON.parse(localStorage.link) : [];
    document.querySelectorAll('a').forEach(a => {
        let href = a.getAttribute('href');
        if (link.includes(href)) a.classList.add('visited')
    })
    document.addEventListener("click", ({ target }) => {
        if (target && target.hasAttribute('href')) {
            let href = target.getAttribute('href');
            if (!link.includes(href)) {
                link.push(href);
                localStorage.link = JSON.stringify(link)
            }
            target.classList.add('visited')
        }
    });
});
</script>
</body>
</html>
Ответить с цитированием