• 判断浏览器及设备的打开方式,自动跳转app中


    如果安装了APP则自动条状app,如果没安装则自动跳转下载页面

    <head>

    放在head中加载

    <script>
    function redirect() {
    var appUri;
    var appStoreUrl;
    var eventId = getQueryString("eventId");
    switch (getDevice()) {
    case "iOS": appUri = "yomovie-thing://?eventId=" + eventId; appStoreUrl = "http://www.baidu.com/thing"; break;
    case "Android": appUri = "yomovie-thing://?eventId=" + eventId; appStoreUrl = "http://cn.bing.com"; break;
    //default: appUri = "#"; appStoreUrl = "";
    }
    if (appUri != undefined) {
    $('<iframe />')
    .attr('src', appUri)
    .attr('style', 'display:none;')
    .appendTo('body');
    setTimeout(function () {
    document.location.href = appStoreUrl
    }, 25);
    }
    }

    function getDevice() {
    var userAgent = navigator.userAgent || navigator.vendor || window.opera;

    if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i) || userAgent.match(/iPod/i)) {
    return 'iOS';
    }
    else if (userAgent.match(/Android/i)) {

    return 'Android';
    }
    else {
    return 'unknown';
    }
    }

    function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
    }

    var browser = {
    versions: function () {
    var u = navigator.userAgent, app = navigator.appVersion;
    return { //移动终端浏览器版本信息
    trident: u.indexOf('Trident') > -1, //IE内核
    presto: u.indexOf('Presto') > -1, //opera内核
    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, //是否为iPhone或者QQHD浏览器
    iPad: u.indexOf('iPad') > -1, //是否iPad
    webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
    };
    }(),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
    </script>
    </head>

    <body>

    放在body中加载
    <script>
    (function () {
    if (browser.versions.mobile) {//判断是否是移动设备打开

    var ua = navigator.userAgent.toLowerCase();//获取判断用的对象

    if (ua.match(/WeiBo/i) == "weibo") {

    //在新浪微博客户端打开
    }
    else if (ua.match(/QQ/i) == "qq") {

    //在QQ微信打开
    }
    else if (ua.match(/MicroMessenger/i) == "micromessenger") {
    //在微信中打开
    }
    else {
    redirect();
    }
    }
    })()
    </script>

    </body>

  • 相关阅读:
    [转] Linux下crontab命令的用法
    [转] Try to use one var statement per scope in JavaScript
    [转] 主流JS框架中DOMReady事件的实现
    MySQL 表复制语句
    [转] MySQL中的运算符展示
    [转] mysql分组取每组前几条记录(排名)
    MySQL 连接结果集
    [转] mysql show processlist命令 详解
    [转] mysql 5.0存储过程学习总结
    jquery中使用event.target的几点
  • 原文地址:https://www.cnblogs.com/wangjiaojiao/p/4583821.html
Copyright © 2020-2023  润新知