var URL_Redireccion_KO = "https://www.abc.es/qr-cp/"; var URL_Redireccion_ActivaGeolocalizacion = "https://www.abc.es/qr-geolocalizacion/"; var CodigoPostalValidos = ["28040"]; function RedireccionaGeolozalizacion () { window.location.href = URL_Redireccion_ActivaGeolocalizacion; } function RedireccionaGeolozalizacionErronea () { window.location.href = URL_Redireccion_KO; } function getUserPostcode () { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( (position) => { let lat = position.coords.latitude, long = position.coords.longitude, url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + long + "&key=AIzaSyCFJzGGAHIeUrJlPvmpGCG68hdGriFCKpk"; $.ajax({ type: "GET", url: url, dataType: "json", success: function (response) { let results = response.results, postalCode = ''; if (results[0]) { for (let i = 0; i < results[0].address_components.length; i++) { let types = results[0].address_components[i].types; for (let typeIdx = 0; typeIdx < types.length; typeIdx++) { if (types[typeIdx] == 'postal_code') { postalCode = results[0].address_components[i].long_name; break; } } if (postalCode !== '') { break; } } } if (CodigoPostalValidos.indexOf (postalCode) > -1 ) { console.log(postalCode); detect(); } else { console.log("KO"); RedireccionaGeolozalizacionErronea(); } }, error: function (req, status, error) { console.log('Sorry, there was an error.'); } }); }, (error) => { switch (error.code) { case error.PERMISSION_DENIED: console.log("User denied the request for Geolocation."); RedireccionaGeolozalizacion(); break; case error.POSITION_UNAVAILABLE: console.log("Location information is unavailable."); RedireccionaGeolozalizacion(); break; case error.TIMEOUT: console.log("The request to get user location timed out."); RedireccionaGeolozalizacion(); break; case error.UNKNOWN_ERROR: console.log("An unknown error occurred."); RedireccionaGeolozalizacion(); break; } } ); } else { console.log("Sorry, Geolocation is not supported by your browser."); RedireccionaGeolozalizacion(); } } function LanzarQR() { try{ if (Voonto) { try{ if ($) getUserPostcode(); else setTimeout(function() {LanzarQR();}, 500); } catch(e) { console.log (e.message); setTimeout(function() {LanzarQR();}, 500); } } else setTimeout(function() {LanzarQR();}, 500); } catch(e) { console.log (e.message); setTimeout(function() {LanzarQR();}, 500); } } window.onload = LanzarQR(); Disfruta gratis de ABC Premium. Continuar