Welcome Guest [Log In] [Register]

About Me

Tips, tricks, and projects from the Generation Studio team. Updated often.
Categories
Code Release (2)
Coding Tips (1)
Other (2)
RPGeneration (2)

Readers Online

0 Members, 1 Guest

Jan 22

ZB Coding Tips #1

I'll be making frequent blog posts detailing the best ways to access certain information in ZB. Today's post goes over some basic things you'll want to know.

Getting the current user's username.
This is one of my most commonly used tricks; often when sending data to a server (more on that in the future), I use this.
Quote:
 
var youUser = $('#top_info strong').text();


Checking if a user is logged in
This is incredibly helpful for making your code not visible to guests. Note: This uses youUser from above.
Quote:
 
var is_logged_in = youUser != "Guest";


Finding out which page a user is on
Great for executing code only on certain pages. On this page, it would contain a string: "blog".
Quote:
 
var currentURL = window.location.href.split(main_url)[1].split("/")[0];


Executing an external script only on certain pages.
This one is critical to keeping load times on a board fast. If you don't use this, external scripts will be downloaded and read even on pages where they aren't needed.
Quote:
 
if (currentURL == "topic")
$('#copyright').append("<script src='http://something.com/scripts/script.js'><\/script>");
Posted at 9:27 pm · No comments
  1. Add new comment: