Reputation: 1640
SECOND UPDATE: With no fix for Safari and a couple other odd behaviors, I decided to create all new boring content for Safari users using this selection (basically giving up on scripting for Safari)...
<?php if($detect->version('Safari')) { ?>
$(function() {
/* create second option because Safari sucks? */
$("#gotorep").remove();
$("#entersite").remove();
$("#entersite2").css({'display':'inline'});
});
<?php } elseif($detect->isMobile()) { ?>
function startfunc() {
if(navigator.geolocation) {
.
.
.
ERROR UPDATE (this was fixed, removed): my error in Safari is 35772ReferenceError: Can't find variable: fail in this location...
$(function() {
if(navigator && navigator.geolocation) {
var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000);
***http://devv.referadiabetic.com/:35772ReferenceError: Can't find variable: fail
navigator.geolocation.getCurrentPosition(
function (pos) {
clearTimeout(fallback);
ORIGINAL QUESTION: I can get this to work in other mobile devices/browsers except Safari. While on the iphone it failed, so reversed the if selection with ! and tested in a Safari desk-top browser with the same issues, not returning my data once I agree. This is the block of code I am working with now...
<?php if(!($detect->isMobile())) { ?>
$(function() {
if(navigator && navigator.geolocation) {
var fallback = setTimeout(function() { fail('10 seconds expired'); }, 10000);
navigator.geolocation.getCurrentPosition(
function (pos) {
clearTimeout(fallback);
var point = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
new google.maps.Geocoder().geocode({'latLng': point}, function (res, status) {
if(status == google.maps.GeocoderStatus.OK && typeof res[0] !== 'undefined') {
var zip = res[0].formatted_address.match(/,\s\w{2}\s(\d{5})/);
if(zip) {
var zipcodepassed = zip[1];
$("#em").html(zipcodepassed);
var reps = reps_load;
var ads_repList_URLtoFullName = ads_repList_URLtoFullName_load;
var rek = ads_repList_URLtoFullName;
var rep = reps[zipcodepassed];
if (rep == undefined || rep == null || rep == "") {
$(function() {
$("#gotorep").remove();
$("#entersite").remove();
$("#entersite2").css({'display':'inline'});
});
}
var repname = rek[rep]; //i.e. shaner will be Shane Reaume in repname variable
$("#yourrep").html(repname);
$("a[href='http://devv.referadiabetic.com']").attr('href', 'http://devv.referadiabetic.com/' + rep);
}
}
});
}
);
}
});
I already have this as a fall back, I am using IP addresses to get zip codes, but because of the nature of mobile devices, I am setting those to perform this block of code.
Upvotes: 0
Views: 784
Reputation: 6346
setTimeout
expects the first parameter to be a string of some code or a call to a function. I believe that it's trying to parse fail
as a string, and... erm... failing.
setTimeout("function() fail('10 seconds expired');", 10000);
Upvotes: 1