[SalesForce] Live Agent: issue with startChat

I am trying to create a very simple Live Agent deployment page, with the link always being displayed (we handle no agent being available in the pre-chat page). Here's the code I put together.

<html>
<body>
<h1>Welcome!</h1>
      Thank you for contacting customer support. 
      <p/>
    <a id="liveagent_button_online_573q000000000Ig" href="javascript://Chat" onclick="liveagent.startChat('573q000000000Ig')">Start Chat</a>

<script type='text/javascript' src='https://c.la3-c1cs-was.salesforceliveagent.com/content/g/js/36.0/deployment.js'></script>
<script type='text/javascript'>
liveagent.init('https://d.la3-c1cs-was.salesforceliveagent.com/chat', '572q000000000Bu', '00Dq00000000VFQ');
</script>

</body>
</html>

When I click on the button, nothing happens, and I see the following error in the JS Console:

Uncaught TypeError: Cannot read property 'startChat' of undefined (deployment.js:68)

Has anyone run into this?

Best Answer

I figured this out, I had to add "liveagent.showWhenOnline" to window._laq, but not "liveagent.showWhenOffline". Here is the working code if anyone is interested:

<html>
    <head>
    </head>
<body>
<h1>Welcome!</h1>
      Thank you for contacting customer support. 
      <p/>
    <a  href="javascript://Chat" onclick="liveagent.startChat('573q000000000Ig')">Start Chat</a>

<script type="text/javascript">
if (!window._laq) { window._laq = []; }
window._laq.push(function(){liveagent.showWhenOnline('573q000000000Ig', document.getElementById('liveagent_button_online_573q000000000Ig')); });
</script>


<script type='text/javascript' src='https://c.la3-c1cs-was.salesforceliveagent.com/content/g/js/36.0/deployment.js'></script>
<script type='text/javascript'>
liveagent.addCustomDetail('spacename', '%placeId%'); 
liveagent.addCustomDetail('ctype', '%cust_type%'); 
liveagent.addCustomDetail('orgid', '%orgid%'); 
liveagent.init('https://d.la3-c1cs-was.salesforceliveagent.com/chat', '572q000000000Bu', '00Dq00000000VFQ');
</script>


</body>
</html>