Open social media links in their respective applications using js

  javascript, jquery, operating-system, python, web

I want to take users from my page directly to social media apps like Instagram, Facebook, Twitter etc. And I would like to know if this can be achieved using JasvaScript. For an example

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            window.onload = function() {

                var desktopFallback = "https://youtube.com/watch?v=4KnNVK-udTU",
                mobileFallback = "https://youtube.com/watch?v=4KnNVK-udTU",
                app = "vnd.youtube://4KnNVK-udTU";

                if( /Android|iPhone|iPad|iPod/i.test(navigator.userAgent) ) {
                    window.location = app;
                    window.setTimeout(function() {
                        window.location = mobileFallback;
                    }, 25);
                } else {
                    window.location = desktopFallback;
                }

                function killPopup() {
                    window.removeEventListener('pagehide', killPopup);
                }

                window.addEventListener('pagehide', killPopup);

            };
        </script>
    </body>
</html>

This code which I found here opens up that respective video in YouTube app according to the device. And here vnd.youtube link is being used for opening in the app.

My question is, is there any similar setup available for other apps which I metioned above?

Or how can I achieve similar output for other apps using js or other languages? My focus is to get similar output for Instagram, Facebook, Twitter. For YouTube the above js snippet is being used.

Thanks for your help 🙂

Source: Python Questions

LEAVE A COMMENT