Solvedish: Chat program -- onclose = leave chat?
Moderator: General Moderators
Solvedish: Chat program -- onclose = leave chat?
Ok, here's my problem. I'm pretty sure my solution will have to be completely javascript, so I'm posting in this forum.
I'm developing one of those live help / talk to an employee web-based chat things.
It's simply done: 3 mysql tables: employee_list, sessions, log
sessions looks something like this: id, clientname, start, end, active
Where start & end are unix timestamps and active is 0 (open), 1 (active), or 2 (closed).
Simple as can be.
So, my question is: What can I do with javascript and onclose to somehow change the `active` field from 1 to 2? I don't want to make a mysql connection if that's even possible. Don't know too much about javascript. I'd just assume run a php file real quick before it all closes. I doubt that's possible either. e.g. onclose='runphpfile("blah.php");' Can something like that work? How?
What are my options?
I'm developing one of those live help / talk to an employee web-based chat things.
It's simply done: 3 mysql tables: employee_list, sessions, log
sessions looks something like this: id, clientname, start, end, active
Where start & end are unix timestamps and active is 0 (open), 1 (active), or 2 (closed).
Simple as can be.
So, my question is: What can I do with javascript and onclose to somehow change the `active` field from 1 to 2? I don't want to make a mysql connection if that's even possible. Don't know too much about javascript. I'd just assume run a php file real quick before it all closes. I doubt that's possible either. e.g. onclose='runphpfile("blah.php");' Can something like that work? How?
What are my options?
Last edited by Skara on Thu Feb 08, 2007 5:53 pm, edited 1 time in total.
If I remember correctly, it's;
The solution would be to have the "closeChat()"-function popup a window (preferably small) requesting "blah.php", which subsequently to execution outputs a javascript closing the popup.
At least, that's how I've seen it implemented numerous times.
Code: Select all
<body onunload="closeChat();">At least, that's how I've seen it implemented numerous times.
-
nickvd
- DevNet Resident
- Posts: 1027
- Joined: Thu Mar 10, 2005 5:27 pm
- Location: Southern Ontario
- Contact:
If they dont allow popups, then they wont be chatting very much, now will they?
onunload works when the window is closed, or if the user navigates away from the current page. I would use an unload function that uses XHR (Ajax) to ping a script on the server that will end the session in the database.
You said you wanted a way to change the record in the database from 1 to 2 (active to closed) without using a database connection...
You must know something we don't
if you want to change something in the database, you MUST have a connection 
onunload works when the window is closed, or if the user navigates away from the current page. I would use an unload function that uses XHR (Ajax) to ping a script on the server that will end the session in the database.
So, my question is: What can I do with javascript and onclose to somehow change the `active` field from 1 to 2? I don't want to make a mysql connection if that's even possible. Don't know too much about javascript. I'd just assume run a php file real quick before it all closes. I doubt that's possible either. e.g. onclose='runphpfile("blah.php");' Can something like that work? How?
You said you wanted a way to change the record in the database from 1 to 2 (active to closed) without using a database connection...
You must know something we don't
It's going to be inline. No popups.nickvd wrote:If they dont allow popups, then they wont be chatting very much, now will they?
Hm. Never used Ajax, I guess this'll be a learning experience.onunload works when the window is closed, or if the user navigates away from the current page. I would use an unload function that uses XHR (Ajax) to ping a script on the server that will end the session in the database.
Thanks. Hopefully this'll solve it.
Hah, ok, bad phrasing. I want to change a value without using javascript to make a connection. ^^;You said you wanted a way to change the record in the database from 1 to 2 (active to closed) without using a database connection...
You must know something we don'tif you want to change something in the database, you MUST have a connection
- tecktalkcm0391
- DevNet Resident
- Posts: 1030
- Joined: Fri May 26, 2006 9:25 am
- Location: Florida
feyd: not sure what you mean..
techtalkcm: they won't be in a popup. It'll be in an inline frame (probably). It /might/ be in a popup, but I'm not sure. In any case, onclose will indeed work. My question was more to do with 'what then?'
I still haven't gotten around to it, but the ajax method above will probably work. If not, I can just make it annoying for an employee to not end a chat. i.e. in the wrong spot, beeping like it's open, etc.
Thanks for the help, I think I got it figured.
techtalkcm: they won't be in a popup. It'll be in an inline frame (probably). It /might/ be in a popup, but I'm not sure. In any case, onclose will indeed work. My question was more to do with 'what then?'
I still haven't gotten around to it, but the ajax method above will probably work. If not, I can just make it annoying for an employee to not end a chat. i.e. in the wrong spot, beeping like it's open, etc.
Thanks for the help, I think I got it figured.