18 lines
612 B
TypeScript
18 lines
612 B
TypeScript
function openInWeChat(url: string) {
|
|
const weChatUrl = `weixin://dl/business/?t=${encodeURIComponent(url)}`;
|
|
window.location.href = weChatUrl;
|
|
// 检测跳转是否成功
|
|
setTimeout(() => {
|
|
if (document.hidden) return;
|
|
alert("未检测到微信,请手动打开微信并访问链接。");
|
|
}, 2000);
|
|
}
|
|
|
|
function checkInWeChat(targetUrl: string) {
|
|
const ua = navigator.userAgent.toLowerCase();
|
|
if (!ua.includes('micromessenger')) {
|
|
openInWeChat(targetUrl); // 调用上述跳转函数
|
|
} else {
|
|
console.log("已在微信内,无需跳转");
|
|
}
|
|
} |