Skip to content

Instantly share code, notes, and snippets.

@braddown
Created August 3, 2012 04:47
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save braddown/3244471 to your computer and use it in GitHub Desktop.
Save braddown/3244471 to your computer and use it in GitHub Desktop.
Link for App Download - Mobile OS Detection and Redirect Download Link to Appropriate App Store
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Redirect</title>
<script type="text/javascript"> // <![CDATA[
//iPhone Version:
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
window.location = "http://goo.gl/IWd7J";
}
//Android Version:
if(navigator.userAgent.match(/android/i)) {
window.location = "http://goo.gl/1K1Hi";
}
//Blackberry Version:
if(navigator.userAgent.match(/blackberry/i)) {
window.location = "http://goo.gl/jH2wD";
}
</script>
</body>
</html>
@napster3p
Copy link

What if we need to redirect user to different page when on desktop or large screen?

@Doufer
Copy link

Doufer commented Jan 10, 2018

}
//Blackberry Version:
if(navigator.userAgent.match(/blackberry/i)) {
window.location = "http://goo.gl/jH2wD";
} else {
window.location = "PLACE THE URL FOR LARGE SCREENS HERE";
}

</script>

@mrramp
Copy link

mrramp commented Jan 12, 2018

Thank you so much!

@tklives
Copy link

tklives commented Feb 14, 2018

This code seems to be missing the </head> and <body> tags (on/before Line 21), otherwise thanks for sharing! 😄

@nesar11
Copy link

nesar11 commented Mar 1, 2018

How can i make link with download button, So user agent would be redirected to thir Android/ Play store or ios / App store
Any body can help me regarding

@neuronetv
Copy link

neuronetv commented Mar 14, 2018

thanks for this code however it doesn't seem to work with samsung galaxy S8 and desktops. If I leave out the

} else {
window.location =

it works for samsung S8 but I also need redirect for desktop pc and with this 'window location' code included the S8 redirect stops working. I expect this is because S8 has hi-res screen. Any ideas to fix this?

@samuelkavin
Copy link

Any idea about close tab or clear url automatically after redirection?

@rczalvarado29
Copy link

Sorry for a stupid question, how can I add button that will trigger the script? =)

@miglav
Copy link

miglav commented Dec 26, 2018

Awesome!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment