Link the same button to a different URL based on the visitors device

Dear all,

I am currently putting together a website and need a solution for the following problem:

On one page, visitors should be able to download a mobile application (either on the App Store or on Google Play) by clicking on a button “download”. The download is triggered by clicking on one download button. Now, when a user accesses the side via its mobile device (mobile view of site) an then clicks on the button “download”, he/she should be directed to the App Store or to Google Play DEPENDING ON whether he/she is using an Android or a iOS device.

Stated in other words: If I am using an iPhone and click on the button “download”, then I am directed into the App Store. However, if I am using an Android phone and click the same button “download”, then I am directed to Google Play.

How do I need to proceed to achieve this result?

Many thanks in advance for sharing your thoughts.

Best regards,

Lionel