Check if URL contains href of link I already clicked

安稳与你 提交于 2019-12-02 10:29:32

Use the Javascript window.location.hash call to determine what the current URL anchor is and base your logic on that:

$('.dropdowner a').click(function (event) {
   if ($(this).attr('href')==window.location.hash){
      return false;
   }
});

This should do what you're looking for - location.hash gives you the current anchor hash from the URL

$(function(){

    $('ul.dropdowner').find('a').click(function() {

        if ($(this).attr('href') == location.hash) {
            return false;
        }

    }

}

This act like you said by default. if the url contain #value1 of any kind it will not duplicate and the url can never looks like : #value1#value1

The following will both disable a link which matches the component of the URL after the # or + as well an enable any previously disabled links:

$('.dropdowner a').on('click', function() {
    var url = window.location,
        tag = url.split('+'),
        hash = window.location.hash,
        supress = function(term) {
            $('.dropdowner a[href=' + term + ']').bind('click', false);
        };      
    $('.dropdowner a').unbind('click', false);
    if (hash) {            
        supress(hash);
    } else if (typeof tag !== 'undefined') {            
        supress('+' + tag);
    }        
});


See:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!