微信 JS 片段

  1 <html>
  2 
  3 <head>
  4     <meta charset="utf-8"/>
  5     <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no,minimal-ui"/>
  6     <meta name="format-detection" content="email=no,telephone=no"/>
  7     <meta name="apple-mobile-web-app-capable" content="yes"/>
  8     <meta name="apple-touch-fullscreen" content="yes"/>
  9     <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
 10     <meta http-equiv="Cache-Control" content="no-cache,no-store,must-revalidate"/>
 11     <meta http-equiv="Pragma" content="no-cache"/>
 12     <meta http-equiv="Expires" content="0"/>
 13     <title>微信测试</title>
 14 </head>
 15 
 16 <body>
 17     <script type="text/javascript">
 18         var putQuery = function putQuery(obj) {
 19             var str = [];
 20             for (var p in obj) {
 21                 if (Object.prototype.hasOwnProperty.call(obj, p)) {
 22                     var v = obj[p];
 23                     str.push((typeof v === 'object') ? putQuery(v) : (encodeURIComponent(p) + '=' + encodeURIComponent(v)));
 24                 }
 25             }
 26             return str.join('&');
 27         };
 28         var getQuery = function(name) {
 29             var reg = new RegExp('(?:^|[?]|&)' + name + '=([^&]*)(?:&|$)', 'i'),
 30                 n = window.location.search || window.location.hash,
 31                 r = n.substr(1).match(reg);
 32             return null !== r ? decodeURIComponent(r[1]) : null;
 33         };
 34         var _t = function() {
 35             return (new Date()).getTime();
 36         };
 37         var _on = function(el, ev, fn) {
 38             if (window.addEventListener) { // modern browsers including IE9+
 39                 return el.addEventListener(ev, fn, false);
 40             } else if (window.attachEvent) { // IE8 and below
 41                 return el.attachEvent('on' + ev, fn);
 42             } else {
 43                 return el['on' + ev] = fn;
 44             }
 45         };
 46         var _off = function(el, ev, fn) {
 47             if (window.removeEventListener) {
 48                 return el.removeEventListener(ev, fn, false);
 49             } else if (window.detachEvent) {
 50                 return el.detachEvent('on' + ev, fn);
 51             } else {
 52                 return elem['on' + ev] = null;
 53             }
 54         };
 55         var closeWin = function(ok, fail) {
 56             return WeixinJSBridge.invoke('closeWindow', {}, function(res) {
 57                 if (res.err_msg === 'close_window:ok') {
 58                     ok && ok(res);
 59                 } else {
 60                     fail && fail(res);
 61                 }
 62             });
 63         };
 64         var hideMenu = function() {
 65             return WeixinJSBridge.call('hideOptionMenu');
 66         };
 67         var hideBar = function() {
 68             return WeixinJSBridge.call('hideToolbar');
 69         };
 70         var getNetType = function(callback) {
 71             return WeixinJSBridge.invoke('getNetworkType', {}, function(res){
 72                 callback && callback(res);
 73                 return WeixinJSBridge.log(res.err_msg);
 74             });
 75         };
 76         if (typeof WeixinJSBridge === 'undefined') {
 77             if(document.addEventListener) {
 78                 document.addEventListener('WeixinJSBridgeReady', wxReady, false);
 79             } else if (document.attachEvent) {
 80                 document.attachEvent('WeixinJSBridgeReady', wxReady);
 81                 document.attachEvent('onWeixinJSBridgeReady', wxReady);
 82             }
 83         } else {
 84             wxReady();
 85         }
 86         var wxReady = function() {
 87         };
 88         var goBack = function() {
 89             history.go(-1);
 90         };
 91         var goTo = function(url) {
 92             window.location.href = url;
 93         };
 94         var isWx = function() {
 95             return /MicroMessenger/i.test(navigator.userAgent);
 96         };
 97         window.onload = function() {
 98             _on(document, 'visibilitychange', function() {});
 99             _on(document, 'webkitvisibilitychange', function() {});
100             _on(window, 'pageshow', function() {});
101             _on(window, 'pagehide', function() {});
102             if (document.hidden) {
103             } else {
104             }
105         };
106     </script>
107 </body>
108 
109 </html>

 

posted @ 2020-06-11 11:51  xlsdg  阅读(56)  评论(0)    收藏  举报