开发者

pause page before redirecting back

开发者 https://www.devze.com 2023-04-08 02:14 出处:网络
I\'d like to make a certain WordPress page pause for a few seconds before redirecting back to the page the visitor was on. The scenario is a redirect page after successful submission of a form. It wil

I'd like to make a certain WordPress page pause for a few seconds before redirecting back to the page the visitor was on. The scenario is a redirect page after successful submission of a form. It will say 'form submitted successfully' or the like for a few seconds, and then redirect back to the page the visitor was on. The redirect is just a simple browser back functionality --

<script type="text/javascript">history.go(-1);</script>

-- in the head, which is easy to add to just that specific page with a custom field. But what can I add to make the page pause for a few seconds before going back? B开发者_开发问答ear in mind that this is a WordPress site with lots of posts so I can't use some kind of body onload redirect back to a specific post with window.location = "the-post-or-page-visitor-was-on";. I need to use the browser's back history to just take the visitor back -1 to whatever page or post they were on, but just pause for a few seconds before doing so.

Thanks a lot.


Try window.setTimeout():

<script type="text/javascript">
  window.setTimeout
  (
    function() { history.go(-1); },
    1000 // 1 second
  );
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消