var token = ''; var tklData;//红包及淘口令数据 $().ready(function () { getToken();//获取token writeLogH5({action:'receiveRedEnvelope-pv',channel:'H5',url:window.location.href});//埋点 }) function double12taoToken (token) { //双十二活动淘宝红包 $.ajax({ type:"post", url:"/api/v2/adzone/double12taoToken", dataType:'json', headers:{ token:token }, data:{ act_id:'1',//活动id(1双十二红包2请期待) }, success:function (res) { if(res && res.errno == 0){ tklData = res.rst.data; $(".copyMask .tkl").html(tklData.wenan); $('#getRedEnvelope').click(function () { //领取红包打开淘宝 writeLogH5({action:'receiveRedEnvelope-opentaobao',channel:'H5',url:window.location.href});//埋点 openTaobao(tklData.m_url) }) $('#getTkl').click(function () { //复制红包掏口领 writeLogH5({action:'receiveRedEnvelope-copytkl',channel:'H5',url:window.location.href});//埋点 copyEvent(tklData.wenan) }) } } }); } //获取token function getToken () { var param = '{"js_callback" : "callBackMethodName"}'; try{ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.app_h5_login.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.app_h5_login(param); } }catch(e){ //TODO handle the exception console.log("兼容") } } function callBackMethodName (data) {//app token 回调 var data = JSON.parse(data) token = data.token; double12taoToken(data.token); } // 打开淘宝 function openTaobao (url) { var param = {"taobaoUrl" : url} param = JSON.stringify(param) if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.app_h5_open_taobao_url.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.app_h5_open_taobao_url(param); } } //关闭弹框 function closeMask () { $(".copyMask").hide(); } function copyEvent (dt) { var data = dt; copy_2.innerHTML = data; copy_1.value = data; if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //区分iPhone设备 window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效 var Url2=document.getElementById("copy_2");//要复制文字的节点 var range = document.createRange(); // 选中需要复制的节点 range.selectNode(Url2); // 执行选中元素 window.getSelection().addRange(range); // 执行 copy 操作 var successful = document.execCommand('copy'); // 移除选中的元素 window.getSelection().removeAllRanges(); }else{ var Url2=document.getElementById("copy_1");//要复制文字的节点 Url2.select(); // 选择对象 document.execCommand("Copy"); // 执行浏览器复制命令 } $(".copyMask").show(); } //toast function showMsg(msg) { var msgBox = document.getElementsByClassName('alert-info')[0]; msgBox.children[0].innerText = msg; msgBox.style.display="block"; setTimeout(function() { msgBox.style.display="none"; }, 1500); } function writeLogH5 (data) { $.ajax({ type:'post', url:'/api/v2/channel/writeLogH5', dataType:'json', data:data, success:function (res) { } }) }