2012-03-23 46 views
0

如果我有一个index.html文件,它包含多个页面。当我加载页面时,我希望URL包含散列#first,又名index.html#first。相反,该URL说index.htmljQuery Mobile是否可以在加载的第一页中显示散列?

我的工作到目前为止是有一个假的第一页,然后直接链接到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> 
+0

可以将假页面放在第一页并从不提及它吗?那会工作吗?或者它必须位于身体的顶部? – uday 2012-03-23 16:08:33

回答

1

你为什么不以JS检查哈希码存在index.html页面上,如果它不是,那么你可以将浏览器重定向到index.html#first

$(function() { 
    if (window.location.hash.length == 0) { 
     window.location = window.location.href + '#first';  
    } 
}); 
0

配置你的Web服务器,以便对于“/”“的index.html” 的处理请求(不带文件路径!)返回301 Moved Permanently响应重定向到“的index.html#第一”

这么说,我无法想象,为什么你想强制哈希o nto网址;也许是一个不够健壮的图书馆?正确编码,http://example.com/,http://example.com/index.htmlhttp://example.com/index.html#first可以和应该(恕我直言)都表现相同。

相关问题