pushState を使用できるかどうかを判断するライブラリを知っている人はいますか?
私はこれを使用していました:
if(window.history.pushState){
window.history.pushState(null, document.title, path);
}else{
location.pathname = path;
}
しかし、Safari 5.0.2 にバグがあり、上記のテストに合格しても機能しないことがわかりました: http://support.github.com/discussions/site/2263-line-links-broken。
他にも落とし穴があるかもしれないと思っており、おそらく誰かがすでにそれらを見つけてまとめていますが、私はまだ何も見つけていません.
編集: @Crescent Fresh
私が見たところ、pushState は履歴スタックにプッシュし、URL を変更するが、location.pathname を更新しないようです。私のコードでは、パスが更新されたかどうかを確認するために setInterval を使用しています。
var cachedPathname = location.pathname;
if(window.history.pushState){
cachedPathname = location.pathname;
setInterval(function(){
if(cachedPathname !== location.pathname){
cachedPathname = location.pathname;
//do stuff
}
}, 100);
}
Safari 5.0.2 では、pushState が URL を変更しても、location.pathname は変更されません。これは、他のブラウザや Safari のバージョンでも機能します。