Hi Everyone,
In this blog, I am going to explain you about javascript code detecting client browser information and redirect accordingly.
By using this code you can detect that the browser runnig on which os or device and use the information for redirect in your function.
Here is the code you need:
isMobile = { Android: function() { return navigator.userAgent.match(/Android/i) ? true : false; }, BlackBerry: function() { return navigator.userAgent.match(/BlackBerry/i) ? true : false; }, iOS: function() { return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false; }, Windows: function() { return navigator.userAgent.match(/IEMobile/i) ? true : false; }, any: function() { return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Windows()); } };
After you can get this information in your function and use accordingly like:
function redirection(){ if ( isMobile.Android() ) { window.location.href = "market://details?id=yourPlayStoreAppId"; } else if ( isMobile.iOS() ) { window.location.href = "https://itunes.apple.com/us/app/YourAppId"; } }
Like this you can detect other browser information.
Thanks
Shakil
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Shakil Pathan
Shakil is an experienced Groovy and Grails developer . He has also worked extensively on developing STB applications using NetGem .