How do we manage to redirect users to the App Store from our download page

How do we manage to redirect users to the App Store from our download page

One of my client need to redirect user to appstore when user load the download page, this is because the client created few stickers with a QR code to download page of the web site. And then user need to click on app store icons to go the the appstore.

So to implement that we added following JS script to the download page

var location = window.location;
var fullUrl = location.href;

var userAgent = navigator.userAgent || navigator.vendor || window.opera;

// iOS detection
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
  window.location.href = "apple app store link";
}
// Android detection
else if (/android/i.test(userAgent)) {
  window.location.href = "google play store link";
}