(function(){
if (!document.getElementById(‘chatway’)) {
var s = document.createElement(‘script’);
s.id = ‘chatway’;
s.src = ‘https://cdn.chatway.app/widget.js?id=EfNmgPZkXxZo’;
s.async = true;
document.head.appendChild(s);
}
})();
(function(){
// Try to open Chatway using whatever global is available
function openChatwayNow() {
try {
if (window.$chatway && typeof window.$chatway.openChatwayWidget === ‘function’) {
window.$chatway.openChatwayWidget(); return true;
}
if (window.Chatway && typeof window.Chatway.open === ‘function’) {
window.Chatway.open(); return true;
}
} catch(e) {}
return false;
}
// Wait for the widget to load, then open
function openWithRetry(maxMs){
const start = Date.now();
const timer = setInterval(function(){
if (openChatwayNow()) { clearInterval(timer); return; }
if (Date.now() – start > maxMs) { clearInterval(timer); fallback(); }
}, 150);
}
// Fallback if the widget is blocked or not authorized
function fallback(){
// Change this to a WhatsApp link or another contact method if you prefer
window.location.href = ‘https://worknowvietnam.com/contact-us/#contact-form’;
}
document.addEventListener(‘click’, function(e){
const btn = document.getElementById(‘chatway-btn’);
if (btn && (e.target === btn || btn.contains(e.target))) {
// Try immediately; if not ready, retry up to ~5s
if (!openChatwayNow()) openWithRetry(5000);
}
});
})();