开发者

append epoch time to a url

Hi I'm trying to append the current epoch time to a url, so onclick it would get a page from the url structured as the following :

http://example.com/grab.php?ans_id=value1&d=epoch time

So for example:

http开发者_Python百科://example.com/grab.php?ans_id=254&d=1308264776271

I can get the epoch time generated in javascript but cant get it appended to the url :(

any help is appreciated


Here is an example. It takes the href of the link you click on, adds the current epoch stamp and sends you to that page.

JSFiddle


Simply put this code in your JavaScript file and then call updateEpoch() to set the epoch in the URL:

function updateEpoch(){
    if(/&d=(.*)/.test(location.href)){
        location = location.href.replace(/&d=(.*)/,"&d="+(new Date().getTime()));
    }else{
        location.href += "&d="+(new Date().getTime());
    }
}

Ad@m

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜