简体   繁体   English

重定向页面特定时间

[英]Redirect a page for a specific time peroid

I am trying to create a 302 redirect which waits for 18 seconds after redirecting and then goes back to the parent page. 我正在尝试创建302重定向,重定向后等待18秒,然后返回到父页面。

Here is what I have done, 这是我所做的,

<script type='text/javascript'>
(function (){
 if (document.cookie.indexOf(welcomeCookie) != -1 ||
     document.cookie.indexOf(dailyWelcomeCookie) != -1
 ){
    document.cookie="toURL"+ "=" +escape(document.URL)+";path=/; domain=.forbes.com";
    document.cookie="refURL"+ "=" +escape(document.referrer)+";path=/; domain=.forbes.com";
    this.location="http://www.forbes.com/fdc/welcome_mjx.shtml";
 })();
</script>

It sounds to me like you need to first redirect the user, which you appear to know how to do. 在我看来,您需要首先重定向用户,您似乎知道该怎么做。 However, once the user is redirected to the target page, that target page will need to have some JavaScript to send the user to the parent page. 但是,将用户重定向到目标页面后,该目标页面将需要具有一些JavaScript才能将用户发送到父页面。 Here's some simple JavaScript code that will do what you need based on your code above: 以下是一些简单的JavaScript代码,这些代码将根据上面的代码完成您需要的工作:

<script type='text/javascript'>
(function (){
if (document.cookie.indexOf(welcomeCookie) != -1 ||
    document.cookie.indexOf(dailyWelcomeCookie) != -1
){
    document.cookie="toURL"+ "=" +escape(document.URL)+";path=/; domain=.forbes.com";
    document.cookie="refURL"+ "=" +escape(document.referrer)+";path=/; domain=.forbes.com";

    // wait 18 seconds then go to the specified page. 18000 milliseconds == 18 seconds
    setTimeout(function(){
        this.location="http://www.forbes.com/fdc/welcome_mjx.shtml";            
    }, 18000); 
})();
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM