Change button on demand without page reload

Sometimes you need "refresh" chat button without page reloading, for example in case of using angularJS or dynamic language switching.

Use button integration code without `LiveAgent.createButton`, so your code will look like:

<script type="text/javascript">
   (function(d, src, c) { var t=d.scripts[d.scripts.length - 1],s=d.createElement('script');s.id='la_x2s6df8d';s.async=true;s.src=src;s.onload=s.onreadystatechange=function(){var rs=this.readyState;if(rs&&(rs!='complete')&&(rs!='loaded')){return;}c(this);};t.parentElement.insertBefore(s,t.nextSibling);})(document,
'//yourdomain.com/scripts/track.js',
   function(e){});
</script> 

Then you can display chat button by this way:

document.body.innerHTML += '<div id="chatButton"></div>';
chatButton = LiveAgent.createButton('BUTTON_ID', document.getElementById("chatButton"));

And destroy by:

if(!LiveAgent.instance.openedWidget) {
    if(document.getElementById(chatButton.elementId)) {
        document.getElementById(chatButton.elementId).parentNode.removeChild(document.getElementById(chatButton.elementId));
    }
    if(document.getElementById("ic" + chatButton.elementId)) {
        document.getElementById("ic" + chatButton.elementId).parentNode.removeChild(document.getElementById("ic" + chatButton.elementId));
    }
    if(document.getElementById("if" + chatButton.elementId)) {
        document.getElementById("if" + chatButton.elementId).parentNode.removeChild(document.getElementById("if" + chatButton.elementId));
    }
    LiveAgent.instance.elements = [];
    LiveAgent.instance.widgets = [];
}

 

Ready to try LiveAgent?

It's free for the first 14 days! No credit card required.

Get Started
We work well with others...
Magento Joomla Wordpress Mailchimp
Contact us

support@ladesk.com

+1-800-811-6590 (Toll Free in USA & Canada)

+421 2 33 456 826 (European Union & Worldwide)

Quality Unit, LLC 616 Corporate Way, Suite 2-3278 Valley Cottage, NY 10989

Stay in touch
Blog Google+
© 2004-2015 QualityUnit.com, All rights reserved