Search code examples
javascriptjqueryhashjquery-address

How to load the current content with jQuery Address plugin on page load?


I am not very familiar with the JQuery Address plugin, but i came up with this code, and its working great, except in this situation: When i click on the "nav a", the url is changed and the content is also changed, but when i am reload the page, the plugin is not triggered by default.

$("#player aside nav a").address(function(event, hash) {
    var rel = $(this).attr('rel');
    $('.ajax_container').hide().removeClass('current');
    $('#player aside nav a').removeClass('active');
    $('#'+rel).show().addClass('current');
    $(this).addClass('active');
    return $(this).attr('href').replace(/^#/, '');  
});

Any idea, how can i trigger this function on page load?


Solution

  • I think you need to look at $.address.externalChange(fn). When I click the back this event will fire and I believe it gives you the hash value.