gpt4 book ai didi

Rails 应用程序中的 Javascript,创建 30 分钟后删除 cookie

转载 作者:行者123 更新时间:2023-11-30 20:49:47 25 4
gpt4 key购买 nike

我有以下正在创建 cookie 的 JavaScript,我想在创建 30 分钟后自动删除此 cookie。

function getGeoLocation() {
navigator.geolocation.getCurrentPosition(setGeoCookie);
}

function setGeoCookie(position) {
var cookie_val = position.coords.latitude + "|" position.coords.longitude;
document.cookie = "lat_lng=" + escape(cookie_val);
}

最佳答案

好的,我可以使用以下内容:

function setGeoCookie(position) {
var cookie_val = position.coords.latitude + "|" + position.coords.longitude;
//declare date and get current date time
var date = new Date();
//add 30 minutes to date
date.setTime(date.getTime() + (30 * 60 * 1000));
//create the expires variable
var expires = "; expires="+date.toGMTString();
//pass the "date" variable to expires properity
document.cookie = 'lat_lng'+"="+cookie_val+expires+"; path=/";

}

关于Rails 应用程序中的 Javascript,创建 30 分钟后删除 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48304886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com