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.