このデモをクリックしてcontent
(index.php?id = id)クリックしてsubject
(index.php)に戻ります。
Q1。(index.php?id = id)直接リンクcontent
ページは利用できません。(index.php)と表示されますsubject
。なぜですか?
Q2。2回目(進む>戻る>進む>戻る)の後に戻るをクリックすると、URLの変更が停止します。なぜですか?(Safari 5)更新:window.onpopstate
URLの使用は正常に機能します。このエラーは発生しません。
任意の提案をいただければ幸いです。
$(window).bind('popstate', function(){
$.ajax({
url:location.pathname,
success: function(data){
$('.container').html(data);
}
});
});
デモ
$('.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>