Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website

Admin
16/10/23
0

Tính tới nay (07.10.2023) cũng đã gầ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 không thể chat được thế là khách out luôn => mất khách.

Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website
Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website 3

Sau nhiều nguồn tham khảo và tìm hiểu, test các kiểu thì mình đúc kết lại được đoạn mã dưới đây. Sẽ giúp bạn sửa được lỗi link chat zalo.me trong thời gian chờ zalo fix 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

Trước khi vào code:

suy nghĩ 1 chút nếu để code sửa lỗi zalo mà phải viết lại button call action hay những nhưng link chat zalo có sẵn trong các bài viết… thì hơi bất cập. Nên mình đã nghĩ cách để code tương thích với mọi kiểu button/link đang có của bất kỳ website nào. Chỉ cần button/link đó có dạng zalo.me/{sđt} là đều dùng được mà không cần thay/thêm/sửa code đang có trên website

Ví dụ cụ thể:

  • Link zalo gốc bị lỗi: https://zalo.me/0912345678
  • Vẫn link đó trên website https://domain.vn/ bạn click vào vẫn chat bt nhé
Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website
Hướng dẫn cách sửa lỗi link zalo.me/{sđt} trên website 4

Code sửa lỗi link zalo.me/{sđt}

Chú ý là bạn không cần sửa gì ở button/link chat zalo của mình cả. Cứ để nguyên như cũ dạng zalo.me/{sđt} nhé

Code này cần thay lại sđt và mã qr code cho đúng. Có thể thêm 01 hoặc nhiều số zalo tuỳ vào web của bạn nha

Các lấy mã qrcode xem video cuối bài nha

Cách chèn code vào WordPress cho người không chuyên ở cuối bài luôn

/*

* Code sửa lỗi link zalo.me/{sđt}

* Author: levantoan.com

*/

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); // Đặt timeout (2.5 giây) để kiểm tra liên kết. Thay đổi số này lên 5000 nếu bạn chưa chạy được

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);

Trong đoạn code trên bạn cần chú ý tới đoạn sau

var zalo_acc = {

"sdtzalo1" : "mã qr code 1",

"sdtzalo2" : "mã qr code 2",

};

Đoạn này chính là sđt zalo của bạn và mã qr code của sđt đó. Ví dụ số zalo lỗi là 0123456 và mã qr lấy dc là abcxyz thì sẽ sửa thành

var zalo_acc = {

"0123456" : "abcxyz"

};

Vậy là xong rồi đó. Còn dưới đây là video hướng dẫn cách lấy mã qr code nha. Code được chia sẻ trên levantoan.com

Hướng dẫn lấy mã Qr code của zalo

Vào zalo > icon Quét mã qr góc trên bên phải > mã Qr của tôi > tải xuống. Sau đó dùng trình quét mã qr hoặc camera của máy điện thoại để lấy link qr code > lấy mã.

  • Link Qr lấy được có dạng: zalo://zaloapp.com/qr/p/xxxxxyz
  • Thì mã cần lấy là: xxxxxyz

Cách chèn code cho bạn không chuyên

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é

1. Làm sao để chèn vào functions.php của web WordPress?

Các bạn có thể dùng code sau để chèn vào functions.php của theme đang kích hoạt nhé. Nhớ đổi thông tin cho đúng

/*

* Code sửa lỗi link zalo.me/{sđt}

* Author: levantoan.com

*/

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. Làm sao để chèn vào flatsome theme

vào menu Flatsome > Advanced > Global Settings > BODY SCRIPTS – BOTTOM sau đó gán code sau vào nhé. Nhớ đổi thông tin cho đúng

<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ành công. Nếu có góp ý sửa đổi gì hãy comment bên dưới nhé

Bình luận bài viết (0 bình luận)

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.