待验证 http://www.w3cfuns.com/article-5601686-1-1.html
function versionCompare(s1, s2) { var v1 = s1.split('.'); var v2 = s2.split('.'); var len = Math.min(v1.length, v2.length); var i; var res = 0; for (i = 0; i < len; i++) { var n1 = parseInt(v1[i], 10); var n2 = parseInt(v2[i], 10); res = n1 - n2; if (res !== 0) { break; } } if (res === 0) { res = v1.length - v2.length; } return res; }; var config = { //快捷方式url appshortcutUrl: 'http://www.gzui.net', //快捷方式Icon appshortcutIcon:'http://img.ucweb.com/s/uae/g/0a/logo_144x144.png', //快捷方式名字 //appshortcutName:'UC-Cricket', appshortcutName:'9Game', //快捷方式添加成功title appshortcutSuccessTitle:'Sent to home screen.' }; var Shortcut = { init: function () { var ua = window.navigator.userAgent; var i = ua.toLocaleLowerCase().indexOf('ucbrowser'); var isUCBrowser = i >= 0; var isAndroid = ua.toLowerCase().indexOf('android') >= 0 ; if (isUCBrowser && isAndroid ){ var ss = ua.substring(i).split('/'); var s = ss[1]; var vc= s.split(' '); var v = vc[0]; // UC浏览器版本号 var c = vc[1]; // UC浏览器内核版本号 //alert(v); //alert(c); this.isU3 = (c.toLowerCase() === 'u3'); // android U3内核允许订阅 this.isMini98Above = (c.toLowerCase !== 'u2' && versionCompare(v,'9.8.0') >= 0); // Android Mini客户端的9.8.0或以上的版本 //alert(this.doms.isMini98Above); if (this.isU3 || this.isMini98Above){ var hasInit = localStorage.getItem('shortcutInit'); if(!hasInit) { //如果快捷图标未被用户添加过 this.addToDesktop() } } } }, addToDesktop:function(){ //创建快捷方式到桌面 if (this.isU3){ var addr = encodeURI(config.appshortcutUrl) + '|' + encodeURI(config.appshortcutIcon) + '|' + encodeURI(config.appshortcutName) + '|'; window.location.href = 'ext:appshortcut:' + addr; window.ucweb.startRequest('shell.notify.toast', [config.appshortcutSuccessTitle]); }else{ window.location.href = 'ext:pinbanner:'; } localStorage.setItem('shortcutInit',true); } }; Shortcut.init();
转载请注明:有爱前端 » 手机端怎么把一个网页添加到桌面