我在使用微信跳转客服场景中发现同样的代码在手机端正常运行,但是PC端会一直重复跳转。关闭页面方法失效,部分代码
setTimeout(function () {
let ua = window.navigator.userAgent.toLocaleLowerCase();
let isWeChat = ua.includes('micromessenger');
if (isWeChat) {
if (typeof WeixinJSBridge !== 'undefined') {
setTimeout(function () {
window.location.href = zlp_redirect;
}, 100);
WeixinJSBridge.invoke('closeWindow');
WeixinJSBridge.call('closeWindow');
} else {
// 监听 WeixinJSBridgeReady 事件确保 WeixinJSBridge 加载完毕后调用
document.addEventListener('WeixinJSBridgeReady', function () {
setTimeout(function () {
WeixinJSBridge.invoke('closeWindow');
WeixinJSBridge.call('closeWindow');
}, 100);
}, false);
}
}
}, 500)