1

When a user click on a button, I wanted them to redirect Different sites based on device type in Email. But after some searching found script tag won't work in JavaScript.

What i tried was -

    <a href="#" onclick="redirect('another_link')">
      Link
    </a>
    function deviceType() {
      const ua = navigator.userAgent;
      if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
        return "tablet";
      }
      else if (/Mobile|Android|iP(hone|od)|IEMobile|BlackBerry|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(ua)) {
        return "mobile";
      }
      return "desktop";
    };

    function redirect(url) {
      if (deviceType() === "desktop") window.open('sample_link', '_blank');
      else window.open(url, '_blank');
    }

As email clients remove script tag, is there any other way to redirect? Thanks.

Tanvir Rahman
  • 651
  • 1
  • 11
  • 31
  • Actually, we don't use JS in an email – Sven Märki Jun 26 '22 at 13:29
  • You could point a link from the email to a site with server side device detection and redirect based on the results from there to the corresponding target site (e.g. with https://github.com/matomo-org/device-detector) – Seybsen Jun 26 '22 at 16:05
  • Does this answer your question? [How to get URL parameter using jQuery or plain JavaScript?](https://stackoverflow.com/questions/19491336/how-to-get-url-parameter-using-jquery-or-plain-javascript) – Nathan Jul 05 '22 at 01:20
  • Use a URL with parameter and the landing page can then analyse that and give you the right content – Nathan Jul 05 '22 at 01:21

0 Answers0