[英]javascript cookie value variable
Cookies應該保存該函數的經度和緯度值,但是我的瀏覽器(chrome)顯示該值未定義。 如何解決經度和緯度坐標成為cookie的值的問題? 其他人問我如何在Cookie上添加變量?
<html>
<head>
<meta charset="UTF-8" />
<title>
HTML Document Structure
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
<!-- Einstellungen zur Defintion als WebApp -->
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>
<div id="wrapper">
<a href="next.html" onclick="geoFindMe()" data-role="button">new chat</a>
</div>
<div class="gradient"></div>
<script type="text/javascript">
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() +
+ (currentdate.getMonth()+1) +
+ currentdate.getFullYear() +
+ (currentdate.getHours()+24) +
+ currentdate.getMinutes() +
+ currentdate.getSeconds();
function geoFindMe() {
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
return;
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.cookie = 'latitude='+latitude+'; '+datetime+'';
document.cookie = 'longitude='+longitude+'; '+datetime+'';
};
function error() {
output.innerHTML = "Unable to retrieve your location";
};
output.innerHTML = "<p>Locating…</p>";
navigator.geolocation.getCurrentPosition(success, error);
}
</script>
</body>
</html>
保存Cookie時未定義latitude
和longitude
...
將cookie保存在成功函數中,而不是頁面加載中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.