• 判断终端类型、微信的文章防盗链、h5页面跳转打开新的app、跳转到app市场


    判断终端的类型、安卓、ios、微信、qq

    function  GetMobelType()  {                
    	var  browser  =   {                    
    		versions:   function()  {                        
    			var  u  =  window.navigator.userAgent;                        
    			return  {                            
    				trident:  u.indexOf('Trident')  >  -1, //IE内核
    				presto:  u.indexOf('Presto')  >  -1, //opera内核
    				Alipay:  u.indexOf('Alipay')  >  -1, //支付宝
    				webKit:  u.indexOf('AppleWebKit')  >  -1, //苹果、谷歌内核
    				gecko:  u.indexOf('Gecko')  >  -1  &&  u.indexOf('KHTML')  ==  -1, //火狐内核
    				mobile:  !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
    				ios:  !!u.match(/(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    				android:  u.indexOf('Android')  >  -1  ||  u.indexOf('Linux')  >  -1, //android终端或者uc浏览器
    				iPhone:  u.indexOf('iPhone')  >  -1  ||  u.indexOf('Mac')  >  -1, //是否为iPhone或者安卓QQ浏览器
    				//iPhone: u.match(/iphone|ipod|ipad/),//
    				iPad:  u.indexOf('iPad')  >  -1, //是否为iPad
    				webApp:  u.indexOf('Safari')  ==  -1, //是否为web应用程序,没有头部与底部
    				weixin:  u.indexOf('MicroMessenger')  >  -1, //是否为微信浏览器
    				qq: u.match(/sQQ/i) == " qq", //是否QQ
    				Safari:  u.indexOf('Safari')  >  -1,
    				  ///Safari浏览器,
    
    				                        
    			};                    
    		}()                
    	};                
    	return  browser.versions;            
    }
    

      截取浏览器地址拼接参数

    //截取地址
    function GetRequest(name) {
    	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    	var r = window.location.search.substr(1).match(reg);
    	if(r != null) {
    		return unescape(r[2]);
    	} else {
    		return null;
    	}
    
    }
    

      跳转到app市场,以微信的为例

    //跳转到app市场
    					var appstore, ua = navigator.userAgent;
    					if(ua.match(/Android/i)) {
    						appstore = 'market://search?q=com.singtel.travelbuddy.android';
    					}
    					if(ua.match(/iphone|ipod|ipad/)) {
    						appstore = "https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8&ign-mpt=uo%3D4";
    					}
    					function applink(fail) {
    						return function() {
    							var clickedAt = +new Date;
    							setTimeout(function() {
    								// To avoid failing on return to MobileSafari, ensure freshness! 
    								if(+new Date - clickedAt < 2000) {
    									window.location = fail;
    								}
    							}, 500);
    						};
    					}
    					$('.footer')[0].onclick = applink(appstore);
    //
    

      在h5页面跳转打开新的app,进行判断(目前还有点小问题,如果有app会打开,再回来这个界面会展示下载的界面)

    function jump(myurl) {	与上面判断ios的方法结合
    	if(GetMobelType.weixin) {
    		alert("是微信啊");// 水土不服就服微信  微信比较牛 第三方app必须在应用宝发布,且开通‘微下载’服务
    	} else {
    		if(GetMobelType.android) {
    			var ifr = document.createElement('iframe');
    			ifr.src = myurl;
    			ifr.style.display = 'none';
    			document.body.appendChild(ifr);
    			//window.location.href = "你要打开的app协议,安卓提供";
    			window.setTimeout(function() {
    				document.body.removeChild(ifr);
    				window.location.href = "下载app的地址";
    			}, 3000);
    		}
    		if(GetMobelType.ios || GetMobelType.iPhone || GetMobelType.iPad) {
    			alert(222);
    			var ifr = document.createElement("iframe");
    			ifr.src = "打开app的协议"; /***打开app的协议,有ios同事提供***/
    			ifr.style.display = "none";
    			document.body.appendChild(ifr);
    			window.setTimeout(function() {
    				document.body.removeChild(ifr);
    			     window.location.href = "下载地址";
    				/***下载app的地址***/
    			}, 2000)
    		};
    	}
    }
    

      处理iframe引入微信的文章防盗链的问题 (这个在微信浏览器打开的时候,会有卡死的现象)

    	$.ajaxPrefilter(function(options) {
    		if (options.crossDomain && jQuery.support.cors) {
    			var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
    				options.url = http + '//cors-anywhere.herokuapp.com/' + options.url;
    		  }
    		});
    		var share_link = that.list.outsideUrl;
    		console.log(share_link)
    		//微信文章地址
    		$.get(
    			share_link,
    			function(response) {
    				//    console.log("> ", response); 
    				var html = response;
    				html = html.replace(/data-src/g, "src");
    				var html_src = 'data:text/html;charset=utf-8,' + html;
    				that.list.outsideUrl = html_src;
    		});
    

      

    ios存在唤起的时候出现原生弹窗的问题,现在接入了第三方,已解决

  • 相关阅读:
    CodeForces 514B
    CodeForces 514A
    UVa 818
    HDU 1003
    UVa百题总结
    UVa 11526
    UVa 12412
    UVa 211
    UVa 1587
    UVa 225 – Golygons [DFS+剪枝]
  • 原文地址:https://www.cnblogs.com/simba-lkj/p/7576415.html
Copyright © 2020-2023  润新知