简体   繁体   English

一次将移动用户重定向到应用下载

[英]Redirect mobile users to app download once

So most of the time as I am browsing the net if I go to a website that has an app it first takes me to a landing page that says bla bla the site is better on the app download it here or "no thanks". 因此,在大多数情况下,当我浏览网络时,如果我转到具有应用程序的网站,则首先将我带到一个登陆页面,该页面显示bla bla该站点在该应用程序上更好,请在此处下载或“不,谢谢”。 Then after you do that it no longer asks you that question. 然后,执行此操作后,它将不再询问您该问题。 what is the easiest way to implement this kind of action? 实施这种行动的最简单方法是什么? Using javascript I can find if a person is on android 使用JavaScript我可以找到一个人是否在Android上

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
    // Do something!
    // Redirect to Android-site?
    window.location = 'http://android.davidwalsh.name';
}

However how do I make this only happen one time? 但是,如何使此操作只发生一次? which page would I add it to? 我要添加到哪个页面? Any ideas? 有任何想法吗? I was thinking cookie but I am not sure if mobile browsers let you add cookies the same way. 我当时在考虑使用cookie,但不确定移动浏览器是否允许您以相同的方式添加cookie。

You could set a cookie on the first visit. 您可以在第一次访问时设置一个cookie。 On the next visit if you detect the cookie you can redirect them immediately. 在下次访问时,如果您检测到Cookie,则可以立即将其重定向。 Something like below (untested): 如下所示(未试用):

var ua = navigator.userAgent.toLowerCase();
    var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

    if(isAndroid) {

        if (document.cookie.indexOf("mobile") >= 0) {

             //user has visited already on mobile so redirect immediately 
              window.location = 'http://android.davidwalsh.name';

           } else {

             expiry = new Date();
             expiry.setTime(date.getTime()+1000000); 

             //First time here - show a message, set a cookie and redirect etc.
             document.cookie = "mobile=yes; expires=" + expiry.toGMTString();
             window.location = 'http://android.davidwalsh.name';

            }

        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM