组保留的标签 余下为需要删除的标签
unset($oldtag[$key]);
}
}
}
if (!empty($oldtag)) {
$tagids = array();
foreach ($oldtag as $tagid => $tagname) {
$tagids[] = $tagid;
}
well_oldtag_delete($tagids, $tid);
}
$r = well_tag_process($tid, $fid, $create_tag, $tagarr);
return $r;
}
// 删除标签和绑定的主题
function well_oldtag_delete($tagids, $tid)
{
$pagesize = count($tagids);
$arrlist = well_tag_find_by_tagids($tagids, 1, $pagesize);
$delete_tagids = array(); // 删除
$tagids = array();
$n = 0;
foreach ($arrlist as $val) {
++$n;
if (1 == $val['count']) {
// 只有一个主题
$delete_tagids[] = $val['tagid'];
} else {
$tagids[] = $val['tagid'];
}
}
!empty($delete_tagids) and well_tag_delete($delete_tagids);
$arlist = well_tag_thread_find_by_tid($tid, 1, $n);
if ($arlist) {
$ids = array();
foreach ($arlist as $val) $ids[] = $val['id'];
well_tag_thread_delete($ids);
}
!empty($tagids) and well_tag_update($tagids, array('count-' => 1));
}
// 标签数据处理 $arr=新提交的数组 $tagarr=保留的旧标签
function well_tag_process($tid, $fid, $new_tags = array(), $tagarr = array())
{
if (empty($tid)) return '';
// 新标签处理入库
if ($new_tags) {
$threadarr = array();
$tagids = array();
$i = 0;
$size = 5;
$n = count($tagarr);
$n = $n > $size ? $size : $size - $n;
foreach ($new_tags as $name) {
++$i;
$name = trim($name);
$name = stripslashes($name);
$name = strip_tags($name);
$name = str_replace(array(' ', '#', "@", "$", "%", "^", '&', '·', '<', '>', ';', '`', '~', '!', '¥', '……', ';', '?', '?', '-', '—', '_', '=', '+', '.', '{', '}', '|', ':', ':', '、', '/', '。', '[', ']', '【', '】', '‘', ' ', ' ', ' ', ' ', ' '), '', $name);
$name = htmlspecialchars($name, ENT_QUOTES);
if ($name && $i <= $n) {
// 查询标签
$read = well_tag_read_name($name);
if ($read) {
// 存在 count+1
$tagids[] = $read['tagid'];
} else {
// 入库
$arr = array('name' => $name, 'count' => 1);
$tagid = well_tag_create($arr);
FALSE === $tagid and message(-1, lang('create_failed'));
$read = array('tagid' => $tagid, 'name' => $name);
}
$tag_thread = array('tagid' => $read['tagid'], 'tid' => $tid);
$threadarr[] = $tag_thread;
$tagarr[$read['tagid']] = $read['name'];
}
}
!empty($threadarr) and tag_thread_big_insert($threadarr);
!empty($tagids) and well_tag_update($tagids, array('count+' => 1));
}
$json = empty($tagarr) ? '' : xn_json_encode($tagarr);
return $json;
}
?> $v = implode(",", $v);
$temp[] = $v;
}
// 去掉重复的字符串,也就是重复的一维数组
$temp = array_unique($temp);
// 再将拆开的数组重新组装
$output = array();
foreach ($temp as $k => $v) {
if ($stkeep) $k = $starr[$k];
if ($ndformat) {
$temparr = explode(",", $v);
foreach ($temparr as $ndkey => $ndval) $output[$k][$ndarr[$ndkey]] = $ndval;
} else $output[$k] = explode(",", $v);
}
return $output;
}
// 合并二维数组 如重复 值以第一个数组值为准
function array2_merge($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array1 as $k => $v) {
isset($v[$key]) ? $arr[$v[$key]] = array_merge($v, $array2[$k]) : $arr[] = array_merge($v, $array2[$k]);
}
return $arr;
}
/*
* 对二维数组排序 两个数组必须有一个相同的键值
* $array1 需要排序数组
* $array2 按照该数组key排序
* */
function array2_sort_key($array1, $array2, $key = '')
{
if (empty($array1) || empty($array2)) return NULL;
$arr = array();
foreach ($array2 as $k => $v) {
if (isset($v[$key]) && $v[$key] == $array1[$v[$key]][$key]) {
$arr[$v[$key]] = $array1[$v[$key]];
} else {
$arr[] = $v;
}
}
return $arr;
}
?>
点击一个按钮,如果手机有安装app的话直接打开app,否则跳转到应用市场下载该app编程频道|福州电脑网
点击一个按钮,如果手机有安装app的话直接打开app,否则跳转到应用市场下载该app
编程之家640
更新时间:2026-04-03 20:31:57 最近在做一个这样的功能,前端网页点击按钮时,如果用户手机有安装该app,则直接打开app;否则就跳到应用市场下载。代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body id="body">
<a href="javascript:;" id="openApp" style="font-size: 30px;">打开客户端</a>
</body>
<script type="text/javascript">
document.getElementById('openApp').onclick = function(e) {
//ios
if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
var browser = navigator.userAgent.toLowerCase();
if(browser.match(/micromessenger/i)) {
//微信内置浏览器
window.location.href ="hengtaixin://";
window.setTimeout(function() {
window.location.href = "https://itunes.apple/us/app/cheng-shi-gao-er-fu/id1008696844?mt=8&uo=4";
}, 1000)
return
} else {
window.location.href ="hengtaixin://"; //ios app协议,由ios同事提供
window.setTimeout(function() {
window.location.href = "https://itunes.apple/us/app/cheng-shi-gao-er-fu/id1008696844?mt=8&uo=4";
}, 2000)
return
}
}
if(navigator.userAgent.match(/android/i)) {
//Android
window.location.href = "app://city_golf";//安卓协议,由安卓同事提供
window.setTimeout(function() {
window.location.href = "http://a.app.qq/o/simple.jsp?pkgname=gr eenjoy.golf.app&g_f=991653"
}, 2000)
return
}
};
</script>
</html>
上面的代码中分为ios,安卓和微信内置浏览器三种情况。实现方法均是window.location.href ="xxx://";首先尝试通过协议来唤醒手机里面的app,如果在2000ms之内跳转成功,则说明手机已经安装app,直接打开,下面定时器的代码将不会执行。如果超过2000ms之后还在这个页面,则证明用户手机没有安装app,则执行定时器里面的代码,跳到应用市场下载。
燃鹅,当我做完这个后,老板突然说加一个这样的功能:如果你的手机已经安装过这个APP,那么上面的“打开客户端”改成“打开APP”,如果没有安装,那就会提示“下载APP”的字样。然后我眉头一皱,这个是否安装app并不是通过判断来实现的呀~~~~~它是直接尝试打开的。。。然后我作为一名职场小萌新瑟瑟发抖地回到自己的座位上开始找相关的资料,一番努力之后,果然没有~~~然后我又去问了几个已经工作了的师兄,,他们也说仅有前端是很难实现的,建议由后端判断然后返回结果给我。。。。
所以现在第二个功能还没有实现,欢迎各位小伙伴有想法的可以不吝赐教~~谢谢!
本文发布于:2025-08-08,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳转到按钮手机市场APP
发布评论