2016-01-08 14 views
0

我使用下面的代碼來重定向在我的網站訪問者:創建重定向鏈接與計算參數

<meta charset="UTF-8"> 
    <meta http-equiv="refresh" content="1;url=http://mylink.com"> 
    <script type="text/javascript"> 
     window.location.href = "http://mylink.com" 
    </script> 

我想日期添加到鏈接,該鏈接變成這樣: 「http://mylink.com/STARTDATE = 2016年1月9日,結束日期= 2016年2月9日

我也想設置開始日期參數設置爲明天的日期和結束日期參數進行度的計算ed基於開始日期的值。

提前致謝!

回答

0

雖然JavaScript是不是你的問題標籤,我會做這樣的事情:

function formatDate(date) { 
    var days = date.getDate(); 
    var months = date.getMonth() + 1; 
    var fixedDays = (days < 10)? ("0" + days) : days; 
    var fixedMonths = (months < 10)? ("0" + months) : months; 
    var result = (1900 + date.getYear()) + "-" 
    + fixedMonths + "-" + fixedDays; 
    return result; 
} 
function createLink(baseUrl, daysExpiration) { 
    var tomorrow = new Date(); 
    tomorrow.setDate(tomorrow.getDate() + 1); 
    var expire = tomorrow; 
    expire.setDate(expire.getDate() + daysExpiration); 
    var result = baseUrl + 
    "/startdate=" + formatDate(tomorrow) + 
    ";enddate=" + formatDate(expire); 
    return result; 
} 
var link = createLink("www.ex.com", 30); 
window.location = link; 

這裏有一個JSFiddle

+0

非常感謝!謝謝。 – Damian