1

Is there a way to systematically check to see if the Chat Widget will be present in a Visualforce page?

I say "will be" present as the html elements are not present on load so you can't check to see if these elements exists on page load. Is there any JavaScript variable or salesforce.com provided method/merge field to determine if Chat is turned on?

  • Not that I'm aware of. What are you trying to do? Is it acceptable to check for the existence of chat via JS after a post-page-load delay? – jkraybill Jul 31 '13 at 1:06
  • Could do that but idealy there is some way to determine this at the onload event. We have a dynamic page layout and need to format based on if the chat is present/will be present. The chat box loads async already (1-2 seconds) after page load so it would be weird/distracting for the UI to shift a few seconds after load. – TehNrd Jul 31 '13 at 5:35
  • Yeah I'd say you're probably out of luck, unless you do some extreme JS hackery. You can see from a session log that there is a JS API in the background that is managing Chat state, but it uses session ID's and is going to be out of bounds from your code/domain even if you wanted to hack into it. AFAIK there is no API exposed for any Chat features. – jkraybill Jul 31 '13 at 6:19
  • I'm totally okay checking for the existence of a JavaScript object that indicates if chat is enabled but I can't seem to find one. – TehNrd Jul 31 '13 at 18:53
  • I'm not a Chat expert, but in looking at my request logs, it looked to me that the chat state (on/off) comes back from the initial asynchronous request. Not sure but I'd suspect that it's unknown at page load, but it would be worth some digging if you're ok with that approach. – jkraybill Aug 1 '13 at 0:47
2

Not ideal but this is what I ended up doing. Calls a function every 50ms after page load for 2 seconds to check for existence of the chat DOM elements.

window.onload = function(){
    //Kick of script that checks for chat widget
    checkForChatWidget(0);
}

function checkForChatWidget(numberOfChecks){
    //Check to see if the chat widget exists
    if(jQuery("#presence_widget").length > 0){
        //Widget loaded, put logic here

    }else if(numberOfChecks < 40){ //If number of checks is greater that 40 (2000ms), stop checking
        setTimeout(function(){
            checkForChatWidget(numberOfChecks + 1);
        },50);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.