Print this page

How to pass values from Start Chat button to Pre-Chat Form

Knowledge Article Number 000206551
Description In Live Agent, sometimes users need to pass some values from the page, where Start Chat button is located, to pre-chat form. Some users use cookies as an option. However, if the Chat button is on a custom domain and prechat form is on domain then that method won't work. This is because browsers don't allow one domain to access cookies from another domain; security issue.
Resolution To achieve this, liveagent.addCustomDetail() function can be used to set the values. On pre chat form page, liveagent.details.preChatInit() function can be used to access those details.

Sample code (Please make sure to test it for all scenarios):

1. This code will be added to the page where you are adding chat button and deployment code
<script type='text/javascript'>
var test = liveagent.addCustomDetail('test','Test Value');

2. Add following code on the pre chat form page
<script type='text/javascript' src=''></script>
<script type="text/javascript">
var detailCallback = function (details){
    for (var i = 0; i < details.customDetails.length; i++) {
        if(details.customDetails[i].label == 'test'){
//First parameter is Chat URL. This is same as generated in Live Chat deployment code and can be used here
//This might be different for different users
//For example, in my Live chat deployment, the chat URL was '' as defined in liveagent.init('', '5724000000000XX', '00De000000XXXXX');

This will allow you to access the details added on first page. Another benefit of this is, these values will also be added to chat transcript to use later 


promote demote