1

I have a WordPress site which and want to provide a download button for my customers which automatically detects which operating system the user has in order to let him download the correct software.

So instead of having two buttons labeled as MacOS and Windows, there should be only one button which figures out what to download link has to be provided.

My guess is it can be done with user agent using JavaScript or PHP but I don't know how to reference it to a specific class or id.

Example: It's like when you want to download the Quicksupport tool for teamviewer. You don't have to choose the OS. It just initializes the download with the correct file.

jkdev
  • 11,360
  • 15
  • 54
  • 77
aditosx
  • 13
  • 3

1 Answers1

0

You could try something like this..

<!DOCTYPE html>
<html>
<body>

<?php
function getAgent() {

  $u_agent = $_SERVER['HTTP_USER_AGENT'];
  if (preg_match('/macintosh|mac os x/i', $u_agent)) {
    $downloadLink = 'macFileUrl';
  } elseif (preg_match('/windows|win32/i', $u_agent)) {
    $downloadLink = 'windowsFileUrl';
  }
  echo "<a href='$downloadLink' download>
  <button>Download</button>
  </a>";
}
getAgent();
?>

</body>
</html>
norcal johnny
  • 2,050
  • 2
  • 13
  • 17
  • If you don't mind, may I ask instead of creating a new button how do I target a header logo (which has a class and an id) – aditosx Jun 13 '19 at 09:02