homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Detect link errors in iOS devices like the iPhone

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

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>

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

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved