我想在页面加载时自动打开hash #home。我试过了
<body onload=window.location='#home'>JS方式:
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "#home";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
</body>
</html> 和html重定向
<meta http-equiv="refresh" content="0; url=#home" />所有的方式都太慢了(大约2-3秒。在页面加载后重定向)。有没有更好(更快)的方法在页面加载时自动打开#home?
发布于 2014-04-06 21:10:56
执行以下操作:
<body onload="window.location.hash='home'">我认为这是最快的方法。
发布于 2014-04-06 21:08:00
要重定向到指定的标签,请使用"home“设置任何div或控件的id。
<html>
<head>
<script type="text/javascript">
function load()
{
window.location.href = "#home";
}
</script>
</head>
<body onload="load()">
<h1>Hello World!</h1>
<div id="home">Some content</div>
</body>
</html> 发布于 2014-04-06 23:24:44
我找到了最佳解决方案。没有加载时间。它检查散列,如果没有散列(第一页加载),则打开散列标签#home。示例:
<script type="text/javascript">
$(document).ready(function(){
var x = location.hash.replace("#","");
if (x==="")
{
window.location.href = "#home";
}
});
</script>真的,我尝试了很多方法,但这是最好和最快的。
https://stackoverflow.com/questions/22894308
复制相似问题