Reputation: 5747
I have a fully functioning messaging system on my website. I want to evolve this by having a box popup altering members when they have a new message.
It would say something like "You have a new message, would you like to view?". You would be able to click Yes or No.
How would I go about doing this? Never tried anything like this before!
Thanks
UPDATE. I am very inexperienced using the technologies required here. How would I go about ensuring this works on every page? What code would I include? This is something I need to improve on as it opens up so many more possibilities!
Upvotes: 0
Views: 1625
Reputation: 5417
You have 3 options:
I'd personally use #1, if I don't need instant user reaction. #2 is good for web chatting. #3 is universal, but rarely used yet.
Normally you would have an AJAX script in the background, running with long timeout (30+ seconds), and functionality that shows the message after page reload. This combines #1 and #2.
Upvotes: 0
Reputation: 57268
Firstly you should look at the following:
http://stanlemon.net/projects/jgrowl.html
you should load jQuery + jGrowl and create a heartbeat function which polls the server every X seconds like.
When the server receives a request from the JavaScript you check the database for the latest messages marked un_notified (not read)
You compile a list and mark them notified, and then send the list to the JavaScript again, this in turn gets passed to jGrowl and notifications are show,
Upvotes: 0
Reputation: 61437
You'd have to check regulary with the server if a new message is present for the user, using a timer in your javascript (so clientside code). Due to the nature of HTTP (it being stateless) it is not possible to push this notification from the server.
Upvotes: 0
Reputation: 2032
You can have a looping AJAX call in the background that checks every few minutes. If the server returns a URL (or something distinguishable from "no messages") then you'll get the popup, and if they hit OK, are sent to the URL (using a basic confirm() dialog in Javascript).
Be careful though, the users patience will wear thin if you munch their CPU power on this.
Upvotes: 1