2016-10-19 12:05


I am using go-gin and have a re-direct

c.Redirect(http.StatusMovedPermanently, myurl1). 

Can I add a timer and call another re-direct once the first one completes in the same handler?

  c.Redirect(http.StatusMovedPermanently, myurl1)
  // sleep for 5 seconds
  c.Redirect(http.StatusMovedPermanently, myurl2)?

Can I pause a handler's execution for a few seconds?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • drmqzb5063 drmqzb5063 5年前

    Simply put inside your page:

    <meta http-equiv="refresh" content="5; url=" />

    Another solution with javascript:

    <script type="text/javascript">
          setTimeout("location.href = '';",5000);

    your html logout page with 3-d party logout page inside

    <!DOCTYPE html>
    <html lang="en">
        <meta http-equiv="refresh" content="5; url=https://localhost:8080/login" />
        <title>Test Layout</title>
        <style type="text/css">
            body, html
                margin: 0; padding: 0; height: 100%; overflow: hidden;
                position:absolute; left: 0; right: 0; bottom: 0; top: 0px;
    <div id="content">
        <iframe width="100%" height="100%" frameborder="0" src="" />
    点赞 评论 复制链接分享
  • doskmc7870 doskmc7870 5年前

    If you want to redirect once the page is loaded, you have to do that in javascript.

    The base of HTTP protocol is 1 query, 1 answer: "Get me this page" -> "Here it is".

    You can't answer once to a query, and one second later and say "Oh, now you have to display this other page" (that's how the protocol was defined).

    Therefore, if you want to redirect to another page after a short break, you have to insert a javascript call at the end of your file: Once the first redirection is done, then JS will execute itself, and you can put something like "Wait 5 seconds then call for this second page".

    点赞 评论 复制链接分享