Welcome to WebmasterWorld Guest from 54.144.243.34

Forum Moderators: open

Detect link errors in iOS devices like the iPhone

   
7:34 am on Sep 1, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month



I created a link that opens in the Google Maps website on desktop computers and in the Google Maps app on iOS devices.

<a href="http://maps.google.com/maps?q=X" id="link">Link</a>

<script>
if(navigator.userAgent.match(/iPhone|iPod/i)) document.getElementById("link").href = "comgooglemaps://?q=X";
</script>


The link, obviously, fails on iOS devices that do not have the Google Maps app by giving this alert: "Cannot Open Page: Safari cannot open the page because the address is invalid."

What I would like to do is silently "catch" url errors and redirect using an Apple Maps link.
8:26 am on Sep 1, 2013 (gmt 0)

5+ Year Member Top Contributors Of The Month



While I'm still trying to do this automatically, I improved my script and now prompt users with a choice:

if(navigator.userAgent.match(/iPhone|iPod|iPad/) && navigator.appVersion.match(/OS \d+_/)[0].slice(3,-1) > 5) $("link").onclick = function(){
window.location = confirm("Use the Google Maps App?") ? "comgooglemaps://?q=X" : "http://maps.apple.com/?q=X";
return false;}
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month