$(function() {
var content = $('#content');
$('a').on('click', function(e) {
History.pushState(null, $(this).text(), $(this).attr('href'));
return false;
});
History.Adapter.bind(window, 'statechange', function() {
var state = History.getState();
content.html('loading...');
$.get(state.url, function(response) {
content.html($(response).filter('#content').html());
});
});
});
I would like to use pushState
to change page content, but actually each content might have different JavaScript to run, there are two ways on my mind to solve it
- write all possible functions in one script, use jQuery
on
to bind the event - put JavaScript inside the
#content
, therefore, when render content will also render the script
First solution will make js file bigger and more complicated, second solution will cause html file ugly, any better solution?