Page 1 of 1

Solvedish: Chat program -- onclose = leave chat?

Posted: Fri Feb 02, 2007 9:34 am
by Skara
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?

Posted: Fri Feb 02, 2007 10:29 am
by feyd
Have the employee handling the chat close it?

Posted: Fri Feb 02, 2007 10:59 am
by Skara
I thought of that, and it may be what I have to do. But I'd rather not--human error and all.

Edit: :!: plus, how would the employee know that the client had left? yeah, the "goodbye" would be a good hint, but you never know. I just want something definite.

Posted: Fri Feb 02, 2007 3:42 pm
by xinnex
If I remember correctly, it's;

Code: Select all

<body onunload="closeChat();">
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.

Posted: Fri Feb 02, 2007 5:15 pm
by Skara
onclose, onunload, same thing. :P

The problem with that is, what if they don't allow popups?
I suppose I can add it anyway, though. Even if it didn't work every time.

Posted: Fri Feb 02, 2007 5:22 pm
by nickvd
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.

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 :) if you want to change something in the database, you MUST have a connection ;)

Posted: Sun Feb 04, 2007 5:25 pm
by Skara
nickvd wrote:If they dont allow popups, then they wont be chatting very much, now will they?
It's going to be inline. No popups. ;)
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.
Hm. Never used Ajax, I guess this'll be a learning experience.
Thanks. Hopefully this'll solve it.
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 ;)
Hah, ok, bad phrasing. I want to change a value without using javascript to make a connection. ^^;

Posted: Sun Feb 04, 2007 5:34 pm
by feyd
Won't be possible without the intervention of Javascript somewhere in there.

Posted: Mon Feb 05, 2007 2:29 pm
by Skara
No, no. Haha. Of course I don't mind using javascript. What I meant to say was I don't want to use javascript to make any connection. I don't mind using it to ping another script on the server to make the connection. ;)
Sorry I'm having trouble explaining myself. :?

Posted: Mon Feb 05, 2007 3:23 pm
by feyd
Having Javascript "ping" another script requires another connection.

Posted: Tue Feb 06, 2007 7:39 pm
by Skara
Ok. This is what you get when you get me at this hour. I won't go into details...
ANYway... I meant a database connection. :oops:

Posted: Tue Feb 06, 2007 9:32 pm
by feyd
The database connection doesn't often live beyond the script making the connection. Also, the database won't automatically update the record without external interaction.

Posted: Tue Feb 06, 2007 11:02 pm
by tecktalkcm0391
Why don't you just have onclose of the window. [If they are already in a popup...it practically has to work] then make another window popup with the php or whatever to do the conncection if you don't want the javascript to do it, and then when its done, have the php output the script window.close()

Posted: Thu Feb 08, 2007 5:53 pm
by Skara
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.