Contributions > Plugins, tips, and tricks

Auto Refresh Chat Status

(1/1)

lionsgate:
Not sure if this has been done, but I came up with some JavaScript to automatically refresh the Chat Image: so if user is on page with chat icon when chat admin changes chat status, the chat icon is updated accordingly as it displays to user. Pretty cool.

1. Add the following JavaScript code between the <head> and </head> tags:

--- Code: ---<script type="text/javascript">
setInterval(function() {
if (document.getElementById('chatimg') != null) {
var myImageElement = document.getElementById('chatimg');
myImageElement.src = '/chat/b.php?i=mgreen&lang=en&?rand=' + Math.random();
}
}, 30000);
</javascript>

--- End code ---

2. Add id="chatimg" to the chat image IMG tag.

* Change /chat/b.php in the Javascript to the relative or absolute URL of your chat.php script.
* Refresh time is 30000 ms or 30 seconds. Feel free to change, but I would not recommend setting too low as it will increase load on the web server.

lionsgate:
BTW, I implemented this here: https://www.password-sentry.com/

There is one issue with using this. You will see a lot of "Visitor navigated..." entries in your Chat Log. Every time chat.php is refreshed, the Chat Log is updated with that entry. Wish there was some way to pass a query to chat.php (via JavaScript call) to skip updating Chat Log to avoid this.

Karinatanemura:
I'm new here and I think what you've posted is useful. I'll try it on my website.  :)

Navigation

[0] Message Index

Go to full version