A Pen by Lastwizard

Thumbnail
This awesome code was written by lastwizard, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright lastwizard ©
  • HTML
  • CSS
  • JavaScript
        <a href='test.html' id='downloadBtn'>werwer</a>
    

/*Downloaded from https://www.codeseek.co/lastwizard/a-pen-by-lastwizard-GqbPVG */
        
    

/*Downloaded from https://www.codeseek.co/lastwizard/a-pen-by-lastwizard-GqbPVG */
        var appUrl = {
  iOS: 'https://itunes.apple.com/app/linkedin/id1052654880?mt=8',
  android: 'http://7xnkds.com2.z0.glb.qiniucdn.com/Flagship-linkedin-release.apk'
};

var userAgentRegex = {
  iOS: new RegExp('iPad|iPhone|iPod'),
  android: new RegExp('android')
};

function createDownloadUrl(redirectDomId, userAgentRegex, appUrl) {
  if (userAgentRegex.iOS.test(navigator.userAgent)) {
    document.getElementById(redirectDomId).setAttribute('href', appUrl.iOS);
  } else if (userAgentRegex.android.test(navigator.userAgent)) {
    document.getElementById(redirectDomId).setAttribute('href', appUrl.android);
  }
}

new createDownloadUrl('downloadBtn', userAgentRegex, appUrl);
    

Comments