max
max

Reputation: 3716

stop link from navigating if js/ajax navigation function exist

so here is my link

    <a href="www.site.com/get_myinfo" onclick="check_navigation_exist('info');" >
 my info </a>

this is what i want

        function check_navigation_exist(wher_togo){

            if(typeof(navigator) != 'undefined'
               && 
            $.isFunction(navigator))
            {
                navigator(wher_togo);
                    return false ;
            }
            else
            return ;


        }




  function navigator(where)
    {
        $('#profile_main').html('<img src="'+image_url+'loader.gif" />');
        $.post(base_url+'profile/'+where , function(data){
            $('#profile_main').html(data);
            if(where != 'get_edit')
            odd();
        })  
    }

    function odd(color){
         color = typeof(color) == 'undefined' ? '#DCEABB' : color ;
         $('tr:odd').css('background-color' , color  );
    }

but it doesn't stop link from navigating

Upvotes: 0

Views: 145

Answers (1)

Daniel Imms
Daniel Imms

Reputation: 50149

You're getting that error because e in not in your parameter list. Normally you will be able to use e.preventDefault() but since you're calling a function in your onclick instead of assigning a function you will need another method as you don't have access to the event.

Try returning false to prevent the default action, and return the result of the function call in your onclick event.

<a href="www.site.com/get_myinfo" onclick="return check_navigation_exist('info');">my info </a>

JS

function check_navigation_exist(wher_togo){

    if (typeof(navigator) != 'undefined' && 
        $.isFunction(navigator))
    {
        navigator(wher_togo);
        return false;
    }
}

Upvotes: 2

Related Questions