开发者

Setting visited on link in jQuery

开发者 https://www.devze.com 2023-03-17 02:23 出处:网络
I catch the click event on certain hyperlinks and instead open a jQuery UI dialog using the href. I return false to avoid the browser doing it too...

I catch the click event on certain hyperlinks and instead open a jQuery UI dialog using the href. I return false to avoid the browser doing it too...

    $('a.previewable').click(function(){
            $('#dialog').html('<img src="'+$(this).attr('href')+'">');
            $('#dialog').dialog({
                    title: 'Preview',
                    width: 350,
                    modal: true
            });
            return false;
    });

It works great but the link color开发者_开发知识库 doesn't change to visited when I click on it. How can I tell the browser the link has indeed been visited?

Thanks!


Well, since you did return false, it hasn't been visited. The best you could probably do is style it.

$(this).addClass('visited');

css

.visited {
    color: purple;
}


These scenarios about adding a custom class are weird. What happens the next time the page is refreshed? Wouldn't you have to track all links that had the visited class and persist that information to a backend so it can be restored on subsequent requests? I'd think all those styles would be wiped out the next request since all logic is being done in memory, client side via JavaScript. The browser would normally maintain a cache and persist that information.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号