IOS opens the JS page logic of the application through the link

Logic: ios opens the app through a link, if not, open the appstore to download

First, you need to determine whether the current ios model is, you can get the identification header through navigator.userAgent to determine the model

After confirming that it is the ios platform, you need to determine whether the current mobile phone is downloading the application. At this time, you can use the url_scheme function of ios to jump to open the application to judge. Set a timeout period. If the app is not opened before this time, it will be considered that the current phone has not downloaded the app, and directly jump to the appstore link of the current app that has been set (the link of the ios app can be searched in the appstore, and click share in the upper right corner to get Is the download link of the application)

The parameters of url_scheme can be obtained by setting the URL of the opened page (url scheme is a kind of identification header, you can open the specified application in ios, you can search for this keyword if you don’t know the url scheme of ios)

For example, the opened webpage is www.aaaa.com/index?name=2&time=1, you can get all the string information after the webpage address [?] character through location.search in js

Finally, attach the html page and logic

<html>
<head>
<script type="text/javascript">
	var u = navigator.userAgent;
	var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
	if(isiOS){
      function ios(){
        
        window.location.href= "urlscheme://com.xxx.xxx?"+location.search; //url_scheme设置的标识头
        window.setTimeout(function(){
           window.location.href = "https://apps.apple.com/cn/app/xxxx/idxxxx"; //appstore链接
        },2000)
      };
	  ios();
}
else
{
	alert('暂时不支持非ios的机型');
}
</script>
</head>
<body>
</body>
</html>

 

Guess you like

Origin blog.csdn.net/ssssssilver/article/details/109857888