Welcome Guest [Log In] [Register]
We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Multiquote (on) Multiquote (off)
Add Reply
Template: how to identify logged-in users?
Topic Started: Sep 4 2011, 10:42 PM (531 Views)
Reera_the_Red
Member
[ * ]
I have a piece of Javascript code that I wish to execute on my board only for logged-in users -- i.e., it should not execute on the log-in screen, so non-members wouldn't see the effects.

This was easy on my InvisionFree board; there's a "userid" cookie that I could check which was absent or zero if a user was not logged in. Unfortunately, on my Zetaboards board, there is no clear equivalent that I can use. There is a cookie which seems to indicate an active session (its name is my board's number followed by "sess", and it goes away when I log out), but it's apparently protected, as I cannot read it via document.cookies.

So -- is there some way that my Javascript code that I'm placing in the board template can determine whether a user is logged in?
Offline Profile Quote Post Goto Top
 
Nicolas
Member Avatar
"PLES RING IF AN RNSER IS REQIRD."

Sure. :)
You can do something simple like this:
Code:
 
if ( $('#top_info small a:contains(Sign Out)').length ) {
alert("User is signed in");
}
You can find a lot more help with things like these on our Official Resource Board.
Offline Profile Quote Post Goto Top
 
Reera_the_Red
Member
[ * ]
Nicolas
Sep 4 2011, 11:40 PM
Code:
 
if ( $('#top_info small a:contains(Sign Out)').length ) {
alert("User is signed in");
}
Sure enough. Silly of me not to have thought of that; thanks! And that will also solve another little puzzle I was trying to work out.

I'll check the Resource Board; thanks for the pointer. I've had my InvisionFree board for several years, but the Zetaboards one is new and I'm still scouting out the possibilities.
Offline Profile Quote Post Goto Top
 
Quozzo-ZNS
Member Avatar
Member
[ *  * ]
i prefere this:
Code:
 
if($('#menu_pm').length){
alert('User is signed in');
};

it has no distinct advantage other than being shorter, and maybe a fraction of a second quicker for the browser too, not that anyone could notice such a thing, but it does add up.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · ZetaBoards - Theme & Code Support · Next Topic »
Add Reply