我在母版页中看到了2个对话框的奇怪行为。基本上我检查GeoLocation是否已启用,如果它已被禁用我会显示一个对话框,告知某些功能在网站禁用时将无效。如果GeoLocation出现错误,我会显示一个不同的对话框,告诉他们存在问题。其中一个对话框大约有50%的时间在工作,有时会显示,有时它会嵌入到我的页面中,只显示文本。另一个Dialog始终只是作为文本嵌入。我想知道它是否正在使用的jQuery版本或者是否存在其他冲突。
这是脚本
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else { $("#message").html("Geolocation is not supported by this browser."); }
function showPosition(position) {
var latlondata = position.coords.latitude + "," + position.coords.longitude;
var latlon = "Latitude" + position.coords.latitude + "," + "Longitude" + position.coords.longitude;
$("#message").html(latlon);
$("[id*=hdnLon]").val(position.coords.longitude);
$("[id*=hdnLat]").val(position.coords.latitude);
// var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
//var geocoder = geocoder = new google.maps.Geocoder();
//geocoder.geocode({ 'latLng': latlng }, function (results, status) {
// if (status == google.maps.GeocoderStatus.OK) {
// if (results[1]) {
// alert("Location: " + results[1].formatted_address + "\r\nLatitude: " + position.coords.latitude + "\r\nLongitude: " + position.coords.latitude);
//}
}
function showError(error) {
if (error.code == 1) {
$("#message").html("User denied the request for Geolocation.");
$("#dialogGeoUserDenied").dialog({
autoOpen: true,
width: 400,
buttons: [
{
text: "Ok",
click: function () {
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("close");
}
}
]
});
}
else if (error.code == 2) {
$("#message").html("Location information is unavailable.");
$("#dialogGeoLocationUnavailable").dialog({
autoOpen: true,
width: 400,
buttons: [
{
text: "Ok",
click: function () {
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("close");
}
}
]
});
}
else if (error.code == 3) {
$("#message").html("The request to get user location timed out.");
$("#dialogGeoLocationUnavailable").dialog({
autoOpen: true,
width: 400,
buttons: [
{
text: "Ok",
click: function () {
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("close");
}
}
]
});
}
else {
$("#message").html("An unknown error occurred.");
$("#dialogGeoLocationUnavailable").dialog({
autoOpen: true,
width: 400,
buttons: [
{
text: "Ok",
click: function () {
$(this).dialog("close");
}
},
{
text: "Cancel",
click: function () {
$(this).dialog("close");
}
}
]
});
}
}
</script>
这是html
<div id="dialogGeoUserDenied" title="Dialog Title">
<p class="validateTips">Geolocation has been disabled on your browser, you will not be able to receive promimity alerts. Enter your zip code to enable them.</p>
<fieldset>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode" value="00000" class="text ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</div>
<div id="dialogGeoLocationUnavailable" title="Dialog Title">
<p class="validateTips">Geolocation is unavailable, you will not be able to receive promimity alerts. Enter your zip code to enable them.</p>
<fieldset>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcodeGU" value="00000" class="text ui-widget-content ui-corner-all">
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</div>