javascript - 时间延迟重定向?

标签 javascript jquery html

我有一个网站,它会滑到我的 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">
                &lt;!--
                    setTimeout("location.href = 'http://www.mysite.co.uk/blog';", 1500);
                --&gt;
                </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/

相关文章:

javascript - 如何针对不同的屏幕尺寸更改语义 UI 侧边栏的位置?

javascript - 使应用程序中加载的 iframe 显示移动网站?

php - 如何使用jquery ajax php上传文件

jquery - 始终显示图像标题,尽管它太长

javascript - 如何添加自定义 css3 动画以及悬停时的过渡?

javascript - 如何获得每行8列? [Javascript, Bootstrap ]

javascript 给出另一个 src 图像的 ID

php - Wordpress 正在生成 400px x 300px 的缩略图,我如何将其更改为 210px x 210px

html - 模仿 css border-image-outset : rounded corner images on transparent background too wide to define as border

javascript - 延迟触发 'onload' 事件