2013-02-15 72 views
0

我试图创建一个302重定向,它在重定向后等待18秒,然后返回到父页面。将页面重定向到特定的时间周期

这里是我做了什么,

<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> 
+1

是源代码页还是目标页代码?你究竟在问什么,如何等待18秒? – bfavaretto 2013-02-15 21:21:06

+0

是您在您的控制下重定向到的页面吗? – SamStephens 2013-02-15 21:32:14

回答

1

这听起来像你对我需要首先将用户重定向,你似乎知道该怎么做。但是,一旦用户被重定向到目标页面,该目标页面将需要一些JavaScript将用户发送到父页面。以下是一些简单的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>