Question

So, there is something wrong with my hashchange... It wont trigger

$('form').submit(function() {
    var form_data = ($(this).serialize());
    window.location.hash = form_data.replace('=','/');
    return false;
});

$(window).on('hashchange', function () {
    var values = window.location.hash.slice(1).split('/');
    $("[name=" + values[0] + "]").val(values[1]);
}
Was it helpful?

Solution

You are missing a closing ); at the end of the second event handler assigment.

$(window).on('hashchange', function () {
    '...';
}); //<= here you had only }

Other than that, it seems to work fine. Unless you are using IE7 of course, which does not support onhashchange (browser support).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top