I using https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js for the cookie function.
My problem is that the cookie seems like deleted after browser restart?
Here are the summary on the code,
if ( $.cookie("latlng") ) {
myLatlng = $.cookie('latlng').split(',');
myLatlng = new google.maps.LatLng(myLatlng[0], myLatlng[1]);
} else {
$.cookie("latlng", "3.139, 101.686", { path: '/' });
myLatlng = new google.maps.LatLng(3.139, 101.686);
}
...
google.maps.event.addListener(marker1, 'dragend', function() {
var temp = marker1.getPosition().lat() + ',' + marker1.getPosition().lng()
$.cookie("latlng", temp, { path: '/' });
});
add an expires value. to expire in 7 days:
$.cookie("latlng", "3.139, 101.686", { path: '/', expires:7 })
If you don't supply any options, $.cookie("MyCookie","MyValue") will create a session cookie for the current path level. That means that the cookie will expire after the browser is closed and will only be available for the current page. By supplyng the options parameter like this:
$.cookie("MyCookie","MyValue", {expires:365})
the cookie will last for a year. You can also include a path in the options to make the cookie available to other pages on you domain like this:
$.cookie("MyCookie","MyValue", {path: '/', expires:365})
whichs creates a cookie that'll last a year and available to all pages on your domain. (which might not what you want if you realize that the cookie will be sent to the server on every page request so use with care).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With