Solvedish: Chat program -- onclose = leave chat?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Solvedish: Chat program -- onclose = leave chat?

Post 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?
Last edited by Skara on Thu Feb 08, 2007 5:53 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have the employee handling the chat close it?
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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 ;)
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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. ^^;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Won't be possible without the intervention of Javascript somewhere in there.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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. :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Having Javascript "ping" another script requires another connection.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post 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()
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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.
Post Reply