*新闻详情页*/>
前几日,协同黑卡意见反馈了1个要求,必须在H5中开启百度搜索APP或是高德APP,因而我在网络上查了有关文本文档,下面放上连接: 1.高德地形图 2.百度搜索地形图
实际思路便是点一下挑选地形图的情况下,先去恳求APP连接,800毫秒后无回应,再自动跳转至H5连接。这样的做法有1点不太好便是无论跳不跳APP,都会跳到H5的连接。有好的念头能够评价1下。
下面放有关编码:
function ToggleAppAndH5( AppUrl , AppCallback = () => {}){ // 先走APP const ifr = document.createElement('iframe'); ifr.src = AppUrl; ifr.style.display = 'none'; document.body.appendChild(ifr); setTimeout(function(){ document.body.removeChild(ifr); }, 3000); // 800毫秒后启用H5连接 let timer = setTimeout(function () { clearTimeout(timer); AppCallback(); }, 800); window.onblur = function () { clearInterval(timer); }; } function Callback(){ // 这里放有关H5连接 if (mapType === 'baidu') { frameDom.attr('src', "http://api.map.baidu.com/direction?origin=latlng:"+ curLat +","+ curLng +"|name:"+ currAddr +"&destination=latlng:"+ elat +","+ elng +"|name:"+ eaddr +"®ion="+ cityName +"&mode=driving&output=html&src=com.youbei.chefu"); } else if (mapType === 'amap') { frameDom.attr('src', "https://ditu.amap.com/dir?type=car&from[lnglat]="+ curLng +","+ curLat +"&from[name]="+currAddr+"&to[lnglat]="+ elng +","+ elat +"&to[name]="+eaddr+"&src=com.youbei.chefu"); } } const u = navigator.userAgent; const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端设备
1. 高德
// iPhone和安卓系统头顶部不1样 let proto = isiOS ? 'iosamap://path' : 'amapuri://route/plan' ; const AppUrl = proto + "?t= 0&slat="+curLat+"&slon="+curLng+"&sname="+currAddr+"&dlat="+elat+"&dlon="+elng+"&dname="+eaddr+"&src=xxx"; ToggleAppAndH5(AppUrl,Callback)
2.百度搜索
// iPhone和安卓系统头顶部不1样 let proto = isiOS ? 'baidumap://' : 'bdapp://' const AppUrl = proto + "map/direction?region="+cityName+"&origin=latlng:"+ curLat+","+ curLng +"|name:"+ currAddr +"&destination=latlng:"+ elat +","+ elng +"|name:"+ eaddr +"&coord_type=bd09ll&mode=driving&src=com.youbei.chefu"; ToggleAppAndH5(AppUrl, Callback)
以上便是本文的所有內容,期待对大伙儿的学习培训有一定的协助,也期待大伙儿多多适用脚本制作之家。
Copyright © 2002-2020 网页设计_移动端网页设计_大一网页设计作业成品_网页编辑软件_网页在线编辑 版权所有 (网站地图) 粤ICP备10235580号