這是最新的寫Javascript變量到<a href> - 不onclick
任何人都知道爲什麼這不會重定向?
function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;
document.getElementById("location").href = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
var redirectUrl = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
}
function redirect()
{
window.location.href = redirectUrl;
}
setTimeout(redirect,15000);
我卡在腦屁模式,似乎無法寫入一個JavaScript變量的錨點href。想法?我敢肯定,我失去了一些東西簡單...
下方,以便JavaScript是拉動全球定位系統 - 正常工作...
我需要它來填充緯度和長成一個錨的href ......沒有一個「onclick」事件 - 需要自動填充......
所以:
<a href="page.htm?Lat=javascript(latitude)&Long=javascript(longitude)">GPS Location</a>
javascript(latitude) - is variable I need to pull from below Javascript
javascript(longitude) - is variable I need to pull from below Javascript
<script type="text/javascript">
function getLocationConstant()
{
if(navigator.geolocation)
{
navigator.geolocation.watchPosition(onGeoSuccess,onGeoError);
} else {
alert("Your browser or device doesn't support Geolocation");
}
}
// If we have a successful location update
function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;
}
// If something has gone wrong with the geolocation request
function onGeoError(event)
{
alert("Error code " + event.code + ". " + event.message);
}
</script>
得到它通過消除VAR想通重定向 – 2012-07-28 15:48:18