Presence Check in JavaScript

Why might you use this?

This is an alternative presence check in JavaScript that is especially useful if you want to display chat boxes for two different queues on the same web page simultaneously, and you do not want to just use raw IFRAMEs. Use this sample code for one of your code chunks, and use the standard code as generated in the Admin site for the other.

Sample Code

This example code that lets you do basic presence checking on page load. The sample code assumes a embedded chat box, but can be easily modified to provide follow-me or pop-up chat box behaviors.

<div id="online" data-myjid="" style="display: none;">
  Queue is online. This can be a pop-up if you don't want an embedded chat box.
  <iframe src=""
  frameborder="1" style="width:190px; height: 275px;"></iframe>
<div id="offline"> Queue is offline. Your offline option here. </div>
<script type="text/javascript"> function show_presence() { for (var i = 0; i < jabber_resources.length; ++i) { var resource = jabber_resources[i]; if ( === 'available' || === 'chat') { document.getElementById('online').style.display = ''; document.getElementById('offline').style.display = 'none'; } } } function check_presence() { var attr = document.getElementById('online').getAttribute('data-myjid'); var jid = attr.split('@'); var url = ['', jid[0], jid[1], 'js'].join('/'); document.write('<script type="text/javascript" src="' + url + '?cb=show_presence"><\/script>'); } check_presence(); </script>

Document URL:

©2021 Nub Games, Inc.