因为项目需求 监控微信个人二维码是否打开
思路:
微信官方并没有提供这个API,经过二维码识别提取到了一个https链接,此类链接微信以及浏览器打开则指向微信官网地址,此思路pass
经过一系列的各种关键字Google到 html5有触摸事件
解决方案:
给img标签添加touchstart touchmove touchend这三个事件,以此监控img标签所活动状态,此方法不能准确使用,只能获取大概
<img id="qrcode" src="/qr/{{:base64_encode($url)}}" ontouchstart="gtouchstart(this)" ontouchmove="gtouchmove(this)" ontouchend="gtouchend(this)">
<script type="text/javascript">
var localqid = localStorage.getItem("localqid");
var qid = "{{$qid}}";
if(null == localqid || '' == localqid) {
localStorage.setItem("localqid",qid);
// $.ajax({url:"{{:url('plus')}}?id="+qid});
}else if(localqid != qid ){
localStorage.setItem("localqid",qid);
// $.ajax({url:"{{:url('plus')}}?id="+qid});
}
var timeOutEvent=0;
function gtouchstart(obj){
timeOutEvent = setTimeout("longPress()",300);
return false;
};
function gtouchend(obj){
clearTimeout(timeOutEvent);
return false;
};
function gtouchmove(obj){
clearTimeout(timeOutEvent);
timeOutEvent = 0;
};
function longPress(){
timeOutEvent = 0;
$("#qrcode").attr('ontouchend','');
$("#qrcode").attr('ontouchmove','');
$("#qrcode").attr('ontouchstart','');
if(null == localqid || '' == localqid){
localStorage.setItem("touch"+qid,"touch");
$.ajax({url:"{{:url('plus')}}?id="+qid});
}else if(localqid != qid ){
localStorage.setItem("touch"+qid,"touch");
$.ajax({url:"{{:url('plus')}}?id="+qid});
}else{
var touch = localStorage.getItem("touch"+qid);
if(null == touch || '' == touch){
localStorage.setItem("touch"+qid,"touch");
$.ajax({url:"{{:url('plus')}}?id="+qid});
}
}
}
</script>
评论 (0)