hello
hello

Reputation: 81

how to hide a link when the browser refresh using jquery

I have a problem how can I remove the link when the browser refreshes it? Here's my code.

    //post cheer!!!!!!!
    $('.comment_likes').live("click",function(e){
        var id          = $(this).attr('rel');
        var url         = $(this).attr('href');
        var thisClass   = this;

        if(like2 == true){
        like2 = false;   

            setTimeout(function(){
                $.post(url,function(data){
                    $(thisClass).fadeOut('slow').fadeIn();
                    $(thisClass).removeClass('remove');
                    $(thisClass).addClass('add');

                    $('#boo_click_'+id).hide();
                    like2 = true;
                });       
            },500);
        }
        return false;
    });

Upvotes: 0

Views: 177

Answers (1)

Lazerblade
Lazerblade

Reputation: 1127

If your page is reloading, you lose any client-side information that gets set on refresh / reload, so you'll need to set a session variable or cookie when the link is clicked, set a javascript variable in the head if the session variable or cookie exists, and check for that variable on page load. If it exists, either don't display the link, or remove the link via jquery (best option is to have conditional code on the server side to determine if the link should be displayed or not - no need to add unnecessary DOM manipulation on page load).

Your other option is to refresh the content via AJAX instead, sans the link, which may actually be faster.

Upvotes: 1

Related Questions