Skip to content

Instantly share code, notes, and snippets.

@zulhfreelancer
Last active October 2, 2018 19:14
Show Gist options
  • Save zulhfreelancer/bee808f9251c4f2dbd87715daa858c04 to your computer and use it in GitHub Desktop.
Save zulhfreelancer/bee808f9251c4f2dbd87715daa858c04 to your computer and use it in GitHub Desktop.
How to detect the device that user is using in InstaPage and redirect them to different URL after they fill-in the form?

How to detect the device that user is using in InstaPage and redirect them to different URL after they fill-in the form?

Example:

Settings > HTML/CSS > Header

<script src="//cdnjs.cloudflare.com/ajax/libs/mobile-detect/1.3.6/mobile-detect.min.js"></script>

Settings > Javascript > Body

$(function() {
    var md           = new MobileDetect(window.navigator.userAgent);
    var ios_url      = "https://itunes.apple.com/...";
    var android_url  = "https://play.google.com/...";
    var fallback_url = "https://www.example.com/";
    if (md.os() == "iOS") {
        console.log("iOS");
        jQuery('form').find('input[name="redirect"]').val(ios_url);
    } else if (md.os() == "AndroidOS") {
        console.log("AndroidOS");
        jQuery('form').find('input[name="redirect"]').val(android_url);
    } else {
        console.log("Desktop");
        jQuery('form').find('input[name="redirect"]').val(fallback_url);
    }
    console.log(jQuery('form').find('input[name="redirect"]').val());
});

That's all.

Thank you to mobile-detect.js for making this happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment