2013-02-15 70 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>