This Demo I want to click forward to content
(index.php?id=id) click back to subject
(index.php).
Q1. (index.php?id=id) direct link content
page not available, it will show (index.php) subject
, why?
Q2. Click back after the second times (forward > back > forward > back) then url will stop change, why? (Safari 5)
update: Use window.onpopstate
url works fine. Not get this error.
Any suggestion will be appreciated.
$(window).bind('popstate', function(){
$.ajax({
url:location.pathname,
success: function(data){
$('.container').html(data);
}
});
});
Demo
$('.subject').click(function(){
$.ajax({
url: 'index.php?id=' + $(this).attr('rel'),
success: function(data){
$('.container').html(data);
}
});
var pageurl;
pageurl = 'index.php?id=' + $(this).attr('rel');
if(pageurl != window.location){
window.history.pushState({path: pageurl}, "", pageurl);
}
return false;
});
index.php
<div class="container">
<?php
if($_GET['id']){
...
print"<div class="content"></div>";
}
else{
...
print"<div class="subject" rel="id"></div>"
}
?>
</div>