Welcome to WebmasterWorld Guest from 54.225.47.94

Forum Moderators: open

Message Too Old, No Replies

Detect link errors in iOS devices like the iPhone

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

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:227
votes: 1


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 Sept 1, 2013 (gmt 0)

Full Member

5+ Year Member Top Contributors Of The Month

joined:Sept 30, 2009
posts:227
votes: 1


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;}
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members