0

index.htmlファイルがあり、複数のページが含まれている場合。#firstページをロードするときに、URL に hash 、akaを含めたいと思いますindex.html#first。代わりに、URL にはindex.html.

これまでの私の回避策は、偽の最初のページを作成してからindex.html#firstに直接リンクすることindex.html#fakeです。

これを行うより良い方法はありますか?

<body>

    <!--
        fake page
    -->
    <div data-role="page" id="fake">
        <div data-role="content">
            fake
        </div>
    </div>

    <!--
        first
    -->
    <div data-role="page" id="first">
        <div data-role="content">
            first
        </div>
    </div>

    <!--
        second
    -->
    <div data-role="page" id="second">
        <div data-role="content">
            second
        </div>
    </div>
</body>
4

2 に答える 2

1

ハッシュ コードが index.html ページに存在する場合は JS をチェックインしてみてください。そうでない場合は、ブラウザを次の場所にリダイレクトできます。index.html#first

$(function () {
    if (window.location.hash.length == 0) {
        window.location = window.location.href + '#first';    
    }
});
于 2012-03-23T16:08:53.810 に答える
0

「index.html」のリクエストと「/」のリクエスト (ファイルのないパス!)301 Moved Permanentlyが「index.html#first」にリダイレクトする応答を返すように、Web サーバーを構成します。

そうは言っても、なぜハッシュをURLに強制したいのか想像できません。おそらく十分に堅牢ではないライブラリですか?正しくコーディングされた 、http://example.com/http://example.com/index.htmlおよびhttp://example.com/index.html#firstcan と should (IMHO) はすべて同じように動作します。

于 2012-03-23T16:21:45.717 に答える