Deep link/ One link for HTML emailer

I am creating an HTML emailer for my client and they want one link for two buttons. when their users do not have their apps installed on their phones, they must be redirected to the default URL. I am not too bright in Javascript / jQuery because I am not able to find answers.
If users have installed their applications on their mobile devices so in this scenario we need the HREF attribute to be changed as per the Android / iOS devices and the application installed on their device if the application is not installed the user will be sent to the default URL.

I tried this method for the execution

<script language=javascript>
<!-- for button 1 -->
    var windowsize = $(window).width();
    $(document).resize(function () {

        $(window).resize(function () {
            var windowsize = $(window).width();
        });
    })
    const getHref = () => {
        const element = document.getElementById("link-change");
        const IS_IPAD = navigator.userAgent.match(/iPad/i) != null;
        const IS_IPHONE = (navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null);

        if (IS_IPAD || IS_IPHONE) {
            element.href = "ios.com"; // 
        }
        else {
            element.href = "default.com"; // default

            if (windowsize < 768) {
                element.href = "android.com"; // default
            }
            else {
                element.href = "default.com"; // default
            }
        };
    };

    getHref();
    const getHref2 = () => {
        const element = document.getElementById("link-change-first");
        const IS_IPAD = navigator.userAgent.match(/iPad/i) != null;
        const IS_IPHONE = (navigator.userAgent.match(/iPhone/i) != null) || (navigator.userAgent.match(/iPod/i) != null);

        if (IS_IPAD || IS_IPHONE) {
            element.href = "ios.com"; // 
        }
        else {
            element.href = "default.com"; // default

            if (windowsize < 768) {
                element.href = "android.com"; // default
            }
            else {
                element.href = "default.com"; // default
            }
        };
    };

    getHref2();

</script>

this worked if the application was installed on the user’s android device only and if the app is not installed on their devices it doesn’t work at all.
for iOS somehow this method is not working at all please let me know how I can achieve the desired outcome