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?

5
  • 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
    Commented Jul 31, 2013 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
    Commented Jul 31, 2013 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
    Commented Jul 31, 2013 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
    Commented Jul 31, 2013 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
    Commented Aug 1, 2013 at 0:47

1 Answer 1

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);
    }
}

You must log in to answer this question.

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