Cách sửa lỗi link zalo chat trên website – Tính tới nay (10.2023) cũng đã hơn nửa năm rồi mà không hiểu vì sao zalo chưa fix vấn đề lỗi khi truy cập vào link zalo.me/{sđt}. Gây ảnh hưởng rất nghiêm trọng tới lượng khách hàng của các website có gán link này trên web. Khách ấn vào chat zalo nhưng nhận lại thông báo không tồn tại tài khoản.
Sau nhiều nguồn tham khảo và tìm hiểu, test các kiểu thì mình chia sẻ giúp bạn sửa được lỗi link chat zalo.me trong thời gian chờ zalo cập nhật sửa lỗi nhé
Hướng giải quyết:
- Tận dụng mã qr code của zalo
- Truy cập trực tiếp tới zalo app qua Deep link chứ không thông qua web zalo nữa
Ưu điểm của code này:
- Tương thích với mọi button/link zale.me/{sđt} trên website đang có
- Không cần sửa lại code của button/link zalo đang có của website
- 1 hay nhiều sđt zalo trên website đều được
- Không cần tạo trang trung gian
- Hỗ trợ iOs, android, pc và trình duyệt nếu pc chưa cài phần mềm zalo
Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website
1. Cách chèn code trực tiếp vào file function wordpress
Code trên là javascript nên các bạn chèn trực tiếp vào file .js của theme là được. Và dưới đây là hướng dẫn cho các bác không chuyên code nhé
/* * Code sửa lỗi link zalo.me/{sđt} */ add_action('wp_footer', 'devvn_fix_zalome', 999); function devvn_fix_zalome(){ ?> <script> var zalo_acc = { "sdtzalo1" : "mã qr code 1", "sdtzalo2" : "mã qr code 2", }; function devvnCheckLinkAvailability(link, successCallback, errorCallback) { var hiddenIframe = document.querySelector("#hiddenIframe"); if (!hiddenIframe) { hiddenIframe = document.createElement("iframe"); hiddenIframe.id = "hiddenIframe"; hiddenIframe.style.display = "none"; document.body.appendChild(hiddenIframe); } var timeout = setTimeout(function () { errorCallback("Link is not supported."); window.removeEventListener("blur", handleBlur); }, 2500); var result = {}; function handleMouseMove(event) { if (!result.x) { result = { x: event.clientX, y: event.clientY, }; } } function handleBlur() { clearTimeout(timeout); window.addEventListener("mousemove", handleMouseMove); } window.addEventListener("blur", handleBlur); window.addEventListener( "focus", function onFocus() { setTimeout(function () { if (document.hasFocus()) { successCallback(function (pos) { if (!pos.x) { return true; } var screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var alertWidth = 300; var alertHeight = 100; var isXInRange = pos.x - 100 < 0.5 * (screenWidth + alertWidth) && pos.x + 100 > 0.5 * (screenWidth + alertWidth); var isYInRange = pos.y - 40 < alertHeight && pos.y + 40 > alertHeight; return isXInRange && isYInRange ? "Link can be opened." : "Link is not supported."; }(result)); } else { successCallback("Link can be opened."); } window.removeEventListener("focus", onFocus); window.removeEventListener("blur", handleBlur); window.removeEventListener("mousemove", handleMouseMove); }, 500); }, { once: true } ); hiddenIframe.contentWindow.location.href = link; } Object.keys(zalo_acc).map(function(sdt, index) { let qrcode = zalo_acc[sdt]; const zaloLinks = document.querySelectorAll('a[href*="zalo.me/'+sdt+'"]'); zaloLinks.forEach((zalo) => { zalo.addEventListener("click", (event) => { event.preventDefault(); const userAgent = navigator.userAgent.toLowerCase(); const isIOS = /iphone|ipad|ipod/.test(userAgent); const isAndroid = /android/.test(userAgent); let redirectURL = null; if (isIOS) { redirectURL = 'zalo://qr/p/'+qrcode; window.location.href = redirectURL; } else if (isAndroid) { redirectURL = 'zalo://zaloapp.com/qr/p/'+qrcode; window.location.href = redirectURL; } else { redirectURL = 'zalo://conversation?phone='+sdt; zalo.classList.add("zalo_loading"); devvnCheckLinkAvailability( redirectURL, function (result) { zalo.classList.remove("zalo_loading"); }, function (error) { zalo.classList.remove("zalo_loading"); redirectURL = 'https://chat.zalo.me/?phone='+sdt; window.location.href = redirectURL; } ); } }); }); }); //Thêm css vào site để lúc ấn trên pc trong lúc chờ check chuyển hướng sẽ không ấn vào thẻ a đó được nữa var styleElement = document.createElement("style"); var cssCode = ".zalo_loading { pointer-events: none; }"; styleElement.innerHTML = cssCode; document.head.appendChild(styleElement); </script> <?php }
2. Hướng dẫn chèn vào theme Flatsome
Đầu tiên các bạn đăng nhập vào admin website. Sau đó chọn Flatsome > Advanced > Global Settings > BODY SCRIPTS – BOTTOM rồi dán code vào nhé.
<script> var zalo_acc = { //"sdtzalo" : "mã qr code" '0982415495': 'hj8as2ynszi2', }; function devvnCheckLinkAvailability(link, successCallback, errorCallback) { var hiddenIframe = document.querySelector("#hiddenIframe"); if (!hiddenIframe) { hiddenIframe = document.createElement("iframe"); hiddenIframe.id = "hiddenIframe"; hiddenIframe.style.display = "none"; document.body.appendChild(hiddenIframe); } var timeout = setTimeout(function () { errorCallback("Link is not supported."); window.removeEventListener("blur", handleBlur); }, 2500); var result = {}; function handleMouseMove(event) { if (!result.x) { result = { x: event.clientX, y: event.clientY, }; } } function handleBlur() { clearTimeout(timeout); window.addEventListener("mousemove", handleMouseMove); } window.addEventListener("blur", handleBlur); window.addEventListener( "focus", function onFocus() { setTimeout(function () { if (document.hasFocus()) { successCallback(function (pos) { if (!pos.x) { return true; } var screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var alertWidth = 300; var alertHeight = 100; var isXInRange = pos.x - 100 < 0.5 * (screenWidth + alertWidth) && pos.x + 100 > 0.5 * (screenWidth + alertWidth); var isYInRange = pos.y - 40 < alertHeight && pos.y + 40 > alertHeight; return isXInRange && isYInRange ? "Link can be opened." : "Link is not supported."; }(result)); } else { successCallback("Link can be opened."); } window.removeEventListener("focus", onFocus); window.removeEventListener("blur", handleBlur); window.removeEventListener("mousemove", handleMouseMove); }, 500); }, { once: true } ); hiddenIframe.contentWindow.location.href = link; } Object.keys(zalo_acc).map(function(sdt, index) { let qrcode = zalo_acc[sdt]; const zaloLinks = document.querySelectorAll('a[href*="zalo.me/'+sdt+'"]'); zaloLinks.forEach((zalo) => { zalo.addEventListener("click", (event) => { event.preventDefault(); const userAgent = navigator.userAgent.toLowerCase(); const isIOS = /iphone|ipad|ipod/.test(userAgent); const isAndroid = /android/.test(userAgent); let redirectURL = null; if (isIOS) { redirectURL = 'zalo://qr/p/'+qrcode; window.location.href = redirectURL; } else if (isAndroid) { redirectURL = 'zalo://zaloapp.com/qr/p/'+qrcode; window.location.href = redirectURL; } else { redirectURL = 'zalo://conversation?phone='+sdt; zalo.classList.add("zalo_loading"); devvnCheckLinkAvailability( redirectURL, function (result) { zalo.classList.remove("zalo_loading"); }, function (error) { zalo.classList.remove("zalo_loading"); redirectURL = 'https://chat.zalo.me/?phone='+sdt; window.location.href = redirectURL; } ); } }); }); }); //Thêm css vào site để lúc ấn trên pc trong lúc chờ check chuyển hướng sẽ không ấn vào thẻ a đó được nữa var styleElement = document.createElement("style"); var cssCode = ".zalo_loading { pointer-events: none; }"; styleElement.innerHTML = cssCode; document.head.appendChild(styleElement); </script>
Chúc các bạn thực hiện thành công!