我有一个网站,它会滑到我的 HTML 中名为博客的“部分”。我希望用户只看到该页面一两秒钟,然后重定向到我的博客引擎。
请建议一个延时重定向?
如果我可以根据博客 li 的点击延迟重定向:
<li data-target="blog" data-target-activation="click" class="tile icon_add_favourite">
<div>
<h2>Blog</h2><h3>13</h3>
<script type="text/JavaScript">
<!--
setTimeout("location.href = 'http://www.mysite.co.uk/blog';", 1500);
-->
</script>
</div>
</li>
更新: 当 HTML5 滑动到部分 block 时,页面仍然使用所有代码呈现,这太奇怪了,因此 JS 应该由点击事件触发,然后运行基于的重定向计时器。
当弹出警告框时,这些解决方案在 JS 中有效。想知道为什么它们在我的页面中不起作用?
最佳答案
编辑:
The problem i face is that HTML5 is all on one index page. So i need the timer to start on click of the blog link.
尝试在博客链接上的点击处理程序中调用 setTimeout,
$('#blogLink').click (function (e) {
e.preventDefault(); //will stop the link href to call the blog page
setTimeout(function () {
window.location.href = "blog.html"; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.
});
尝试使用 setTimeout
函数,如下所示,
setTimeout(function () {
window.location.href = "blog.html"; //will redirect to your blog page (an ex: blog.html)
}, 2000); //will call the function after 2 secs.
关于javascript - 时间延迟重定向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9877263/