2

Android ブラウザが を正しく実装していないようwindow.location.replaceです。

ほとんどのブラウザでは、呼び出しwindow.location.replaceによって現在の URL が渡された URL に置き換えられます。

ユーザーが別の場所に移動してからクリックして戻ると、呼び出されるwindow.location.replace前の URL ではなく、に渡された URL に戻りますwindow.location.replace

Android ブラウザはこれを適切に実装していないようです。

Android ブラウザでは、ユーザーは に渡されたURLではなく、元の URL にリダイレクトされwindow.location.replaceます。

ここでこれを自分でテストできます。

Androidで履歴を書き換える別の方法はありますか? それとも、Android ユーザーの場合、その機能なしで生活する必要がありますか?

4

4 に答える 4

2

私は同じ問題を抱えていて、クリスの提案に似たコードになってしまいましたが、if ステートメントを変更して、modernizr の機能検出を使用しました。modernizr を使用していない場合、コードは次のようになります。

if(!!(window.history && history.replaceState)){
   window.history.replaceState({}, document.title, base + fragment);
} else {
   location.replace(base + fragment);
}

デバイス検出の特定の理由がない限り、機能検出は基本的にすべてのデバイスをサポートし、将来のデバイスもサポートするため、優先されます。

于 2014-05-01T05:52:08.253 に答える
1

すべて/ほとんどのモバイルプラットフォームで機能させるには、このリンクを確認してください。

Android、iPad、iPhoneのリダイレクトを処理する方法を示します。

Androidは使用しますdocument.locationが、iOSはサポートしますwindow.location.replace

于 2013-03-04T02:04:01.933 に答える
0

これは機能しますか?

document.location.href = 'http://example.com/somePage.html';
于 2013-03-04T02:04:43.300 に答える
0

履歴ウィンドウで replaceState メソッドを使用してみることができます。

      if (((navigator.userAgent.toLowerCase().indexOf('mozilla/5.0') > -1 && navigator.userAgent.toLowerCase().indexOf('android ') > -1 && navigator.userAgent.toLowerCase().indexOf('applewebkit') > -1) && !(navigator.userAgent.toLowerCase().indexOf('chrome') > -1))) {
          window.history.replaceState({}, document.title, base + fragment);
      } else {
          location.replace(base + fragment);
      }
于 2013-07-05T10:22:31.977 に答える