When open live agent sandbox page it will :

  1. detect liveagent.
  2. show/hide pre-chat button by liveagent is available or not.

so I have to manually click the button then start the prechat page. However what I need is :

  1. detect liveagent
  2. Auto redirect to prechat page when there is liveagent

Currently I handle it by detect the button attribute change and use javascript to trigger its click, but I think it is a sneak way.

Is there any sample / api document to solve this? Really appreciate any hint or idea, thanks first.

Hint live_agent_sandbox_page.html

        <script type='text/javascript' src='https://c.la9cs.salesforceliveagent.com/content/g/js/34.0/deployment.js'></script>
        <script type='text/javascript'>
            liveagent.init('https://d.la9cs.salesforceliveagent.com/chat', 'DeploymentId', 'Org_Id');
        <button id="liveagent_button_online_buttonID" href="javascript://Chat" style="display: none;" onclick="liveagent.startChat('buttonID')">
            Online Chat Content 
        <div id="liveagent_button_offline_buttonID" style="display: none;">
            Offline Chat Content
        <script type="text/javascript">
            if (!window._laq) { window._laq = []; }
            window._laq.push(function(){liveagent.showWhenOnline('buttonID', document.getElementById('liveagent_button_online_buttonID'));
            liveagent.showWhenOffline('buttonID', document.getElementById('liveagent_button_offline_buttonID'));

1 Answer 1


You can use the event callback for the chat button. The callback function will automatically be called whenever status of the chat button changes. You would still need to use javascript to trigger the button click.

function btnEventHandler(e){
    if(e == liveagent.BUTTON_EVENT.BUTTON_AVAILABLE){
    }else if(e == liveagent.BUTTON_EVENT.BUTTON_UNAVAILABLE){

liveagent.addButtonEventHandler('buttonID', btnEventHandler);

liveagent.init('https://d.la2c1.salesforceliveagent.com/chat', 'DeploymentId', 'Org_Id');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .