Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(function () {
function loadZendeskChat(callback) {
var zdscript = document.createElement('script');
zdscript.setAttribute('id','ze-snippet');
zdscript.src = 'https://static.zdassets.com/ekr/snippet.js?key=XXX-XXX-XXX-XXX';
(document.getElementsByTagName('body')[0]).appendChild(zdscript);
window.zdonload = setInterval(function(){
if(typeof zE !== "undefined" && typeof zE.activate !== "undefined") {
clearInterval(window.zdonload);
callback();
}
},50,null)
};
window.loadAndOpenZendeskChat = function() {
var button = document.getElementById('zdbutton');
localStorage.setItem('ff_zd_hasOpened',true);
button.innerHTML = 'Loading...';
loadZendeskChat(function(){
window.setTimeout(function(){
zE.activate();
button.parentNode.removeChild(button);
},1000);
});
}
if(localStorage.getItem('ff_zd_hasOpened')) {
loadZendeskChat(function(){});
} else {
document.getElementsByTagName('body')[0].insertAdjacentHTML('beforeend','<button id="zdbutton" aria-label="Launch Help Chat Window" onClick="window.loadAndOpenZendeskChat();">Help</button>');
}
}());
@Mibo999

This comment has been minimized.

Copy link

@Mibo999 Mibo999 commented Sep 15, 2020

Hi,

does this script work ?

Regards

Mikael

@JJCLane

This comment has been minimized.

Copy link

@JJCLane JJCLane commented Jan 29, 2021

Just a little update, rather than introducing a race condition with the setTimeout, you can wait for zE to be ready:

zE(() => {
    zE.activate();
    button.parentNode.removeChild(button);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment