175

?ウィンドウ内のハッシュ ポップ状態を制御するために、URL に が含まれているかどうかを確認しています。IE だけで、他のすべてのブラウザには問題がありません。

この方法でロードしようとすると、デバッガーから次のエラーが表示されます。

includesオブジェクトはプロパティまたはメソッド ' 'をサポートしていません

popstate からページを読み込んでもエラーは発生しません。

    $(document).ready(function(e) {
        if(window.location.hash) {
            var hash;
            if(window.location.hash.includes("?")) {
                alert('I have a ?');
                hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?'));
            }else {
                hash = window.location.hash;
            };
            if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){
                $(hash+'Content').addClass('pageOn').removeClass('pageOff');
            }else {
                $('#homeContent').addClass('pageOn').removeClass('pageOff');
            };
        } else {
            $('#homeContent').addClass('pageOn').removeClass('pageOff');
        }
        $(window).on('popstate', function() {
            var hash;
            if(window.location.hash.includes("?")) {
                hash = window.location.hash.substring(window.location.hash.indexOf('#') + 0,window.location.hash.indexOf('?'));
            }else {
                hash = window.location.hash;
            };
            if (hash=="#DRS" || hash=="#DRP" || hash=="#DFFI" || hash=="#DCI" || hash=="#DCP" || hash=="#DRP" || hash=="#DRMA" || hash=="#EICS" || hash=="#ORG"){
                $(this).navigate({target: $(hash+'Content')});
                if(window.location.hash.includes("?")) {
                }else{
                    location.href = location.href+'?';
                }
            }else {
                $(this).navigate({target: $('#homeContent')});
            };
        });
});
4

8 に答える 8

243

MDN リファレンス ページによると、はincludesInternet Explorer ではサポートされていません。最も簡単な代替方法はindexOf、次のように を使用することです。

if(window.location.hash.indexOf("?") >= 0) {
    ...
}
于 2015-06-29T15:21:43.523 に答える
6

Internet Explorer と同様に、javascript メソッド「includes」がサポートされていないため、以下のエラーが発生します。

dijit.form.FilteringSelect TypeError: オブジェクトはプロパティまたはメソッド 'includes' をサポートしていません

そこで、以下のように JavaScript 文字列メソッドを「includes」から「indexOf」に変更しました。

//str1 doesn't match str2 w.r.t index, so it will try to add object
var str1="acd", str2="b";
if(str1.indexOf(str2) == -1) 
{
  alert("add object");
}
else 
{
 alert("object not added");
}
于 2016-04-01T10:52:09.823 に答える
1

私はReactJsを使用import 'core-js/es6/string';しており、最初にindex.js問題を解決するために使用しました。

import 'react-app-polyfill/ie11';また、IE11 での React の実行をサポートするために使用しています。

反応アプリポリフィル

このパッケージには、さまざまなブラウザー用のポリフィルが含まれています。Create React App プロジェクトで使用される最小要件と一般的に使用される言語機能が含まれています。

https://github.com/facebook/create-react-app/blob/master/packages/react-app-polyfill/README.md

于 2019-03-26T12:35:38.870 に答える