Author Topic: Auto Refresh Chat Status  (Read 16226 times)

0 Members and 1 Guest are viewing this topic.

lionsgate

  • Full Member
  • ***
  • Posts: 10
    • LionsGate Creative
Auto Refresh Chat Status
« on: March 10, 2014, 04:53:43 AM »
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: [Select]
<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>

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

  • Full Member
  • ***
  • Posts: 10
    • LionsGate Creative
Re: Auto Refresh Chat Status
« Reply #1 on: March 10, 2014, 05:41:36 AM »
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

  • Jr. Member
  • **
  • Posts: 1
Re: Auto Refresh Chat Status
« Reply #2 on: May 02, 2015, 07:45:23 AM »
I'm new here and I think what you've posted is useful. I'll try it on my website.  :)