homepage Welcome to WebmasterWorld Guest from 54.196.194.204
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
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
ocon




msg:4606540
 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>

<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.

 

ocon




msg:4606549
 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