Dd MarcoFeaFeaTach Champe d'AjonFem Traopddégidence Marco illustrdd Marco illustrdd MarcoAdéldice Traopenetdachachachach illustrddachach

J'ai besoin de faire des boutons de retour et d'avance fonctionnant avec cette méthode ajax
Ce code fonctionne bien et l'URL sur le navigateur change comme il se doit
Mais lorsque vous cliquez sur les boutons arrière et avant, rien ne se passe

(function(){ function clickNav(e){ e.preventDefault(); var href = $(this).attr('href'); history.pushState(null, null, href); $.ajax({ url: href, dataType: 'html', cache: false }).done(function(html){ var $html = $(html); $('title').html($html.filter('title').text()); $('#content').replaceWith($html.find('#content')); $('#nav').replaceWith($html.find('#nav')); $('#nav li a').on('click',clickNav); }); } $('#nav li a').on('click',clickNav); })(); 

J'ai dû faire face à cela aujourd'hui. Ce qui suit fonctionne pour moi (testé sur quatre navigateurs dans Win 7 jusqu'à présent) …

 //CHECK FOR ADDRESS BAR CHANGE EVERY 500ms var wwcint = window.setInterval(function(){ if(window.last_location_href == undefined) { window.last_location_href = document.location.href; } else if(window.last_location_href != document.location.href) { window.last_location_href = document.location.href; //DO WHATEVER YOU NEED TO DO TO LOAD THE CORRECT CONTENT someFunctionToLoadTheContent(document.location.href); } }, 500); 

C'est parce que votre histoire est vide. Pour cela, vous devez utiliser

  history.pushState(); 

Ensuite, mes boutons commencent à fonctionner