微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

再次访问同一链接不会在野生动物园中触发onload事件

如何解决再次访问同一链接不会在野生动物园中触发onload事件

我正在使用以下JavaScript检查移动应用是否已安装。如果已安装,则启动应用程序或将用户带到AppStore / PlayStore。

当我点击电子邮件中的链接时,它会在浏览器中打开并正常工作。但是,如果我返回电子邮件并点击同一链接,则不会再次触发onload事件,并且浏览器显示永无休止的加载。有什么问题吗?

注意:如果我刷新页面或复制并粘贴链接,则可以。

'''

<!DOCTYPE html>

<html>
<head>
<Meta charset="utf-8">
    <Meta name="apple-mobile-web-app-capable" content="yes" />
    <Meta http-equiv="cache-control" content="no-cache,must-revalidate,post-check=0,pre-check=0" />
    <Meta http-equiv="cache-control" content="max-age=0" />
    <Meta http-equiv="expires" content="0" />
    <Meta http-equiv="expires" content="Tue,01 Jan 1980 1:00:00 GMT" />
    <Meta http-equiv="pragma" content="no-cache" />
    
    <script type="text/javascript">
    
    
        var androidplayStore = "https://play.google.com/store/apps/details?id=com.xxxxx.mobile.android&hl=en_IN";
        var appleAppStore = "itms-apps://itunes.apple.com/app/idxxxxxxx";
        var urlSchema = "myapp://activateuser?code=123456";
        
        
        function getPlatform() {
            
            var platform = null
            
            if (navigator.userAgent.match(/iPad/i) != null) {
                platform = "iOS"
            } else if (navigator.userAgent.match(/iPhone/i) != null) {
                platform = "iOS"
            } else if (navigator.userAgent.match(/iPod/i) != null) {
                platform = "iOS"
            } else if (navigator.userAgent.match(/android/i) != null) {
                platform = "Android"
            }
            
            return platform
        }
         
        // open AppStore/Play store
        function openAppStore(platform) {
        
            try{
                if(platform == "iOS")  {
                    window.location.href = appleAppStore;
                } else if(platform == "Android") {
                    window.location.href = androidplayStore;
                }
            } catch(e){
                
            }
        }
    
        function checkIfAppInstall() {
        
            var platform = getPlatform();
            var urlScheme = null
            
            if(platform == "iOS") {
                urlScheme = urlSchema;
            }else if(platform == "Android") {
              urlScheme = urlSchema;
            }
            
            if (urlScheme != null) {
                setTimeout( function() {
                    openAppStore(platform);
                },500);
               window.location.href = urlScheme;
            }
         
            return true;
        }
    
        window.onload = function() {
            alert("Hello! onload!");
          
            try {
                checkIfAppInstall();
            }
            catch(e) {
                // Eat error
            }
            
        };

    </script>
</head>

<body></body>  
</html>

'''

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。