I found out this quite a while ago but wanted to check a few things before posting about it.
Its a mixture of things, added together can create something quite useful. Let me explain, with the chatbox:
- If you try and send an empty message the form does not send.
- If you send an empty message via ajax, it does not get added to the message list.
- If you are logged out and send a message (empty or not), then you get logged in.
Combining these three things together, if you send an empty message via ajax whilst not logged into the chatbox, you will be logged on.
Now previously, creating an automatic log in to the chatbox was only possible if you could access the function [ic]CB_disconnect()[/ic] which was only in the main '/chatbox' page. Which as you know our Javascripts are not included in. However, with these three points above, I'll show you today that it is now possible to automatically log a user into the chatbox via sending an empty message with ajax
These codes should only be set for 'Homepage only'This code will log a user into the chatbox: [ic]$.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent=');[/ic] So now, lets get creative with it.
This code will make it so that when the user clicks the 'Chatbox' or 'Join the chat' links in the index page that they will be logged in as the chatbox opens (tested only in phpbb3):
- Code:
[panda=js]$(function(){
var c = document.getElementById('chatbox_popup');
$(c.previousSibling.previousSibling).add(c).click(function(){
$.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent=');
});
});
OR, if you want them to be logged in as soon as they log into your forum:
- Code:
[panda=js]$(function(){
if(document.getElementById('logout')) $.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent=');
});
OR, how about we set a cookie, so we only auto log them in once per session, then the rest is up to them.
- Code:
[panda=js]if(my_getcookie('cb_login') != '1') {
$.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent=');
my_setcookie('cb_login', '1', false);
}
OR, maybe you want to make your own link which will open the chatbox in a new tab/window and log them in at the same time: [ic]<a href="/chatbox" target="_blank" onclick="$.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent=');">Go to chatbox</a>[/ic]
You can even use this, to get rid of the timeout in the chatbox!
- Code:
[panda=js]setInterval(function(){ $.post('/chatbox/chatbox_actions.forum?archives','mode=send&sent='); }, 5000);
This will send that empty message off every 5 seconds, meaning if the user gets logged out, then within 5 seconds at the most he will get logged back in.
And the best bit is, the chatbox pages do not count towards your HTTP Request limit that forumotion has set, because if it did, just chatting to people would make us hit the limit.
That's the best bit, this is Ajax that you don't even have to worry about hitting the request limit with.So there you have it, remember it came from AvacWeb first, auto-logging into the chatbox no matter what your situation is, and even create the effect the time out isn't there!#tips #AWC