1

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?

2
  • Notice that you are using "button_online", which only works when an agent is online. Commented Mar 14, 2016 at 21:55
  • Rob, thanks for your comment. But that is nothing more than the id of the link element, removing that made no difference.
    – hamayoun
    Commented Mar 15, 2016 at 13:26

2 Answers 2

4

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>
0

Every time I got that error was because the method

liveagent.showWhenOnline('YOUR_ID_HERE', document.getElementById('your_element')); 

was using one ID and then, the

onclick="liveagent.startChat('YOUR_ID_HERE')" 

was using a different ID. Try to make sure you have the same ID on both places.

And make sure you check if the Button Id is online or not using showWhenOnline, otherwise Deployment.js won't able to open the chat.

You must log in to answer this question.

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