JavaScript: Do More with Ka.Info!

by Mauvis

About Ka.Info

The Ka.Info JavaScript object is on all KickApps-powered pages and contains basic information about the site, the logged-in user, and the current page details. You can use this object to extend the capability of your site even further, and target your code for specific pages, sections, or even users.

*The Ka.Info object never contains sensitive information such as passwords.

Here is a list of things you can do using Ka.Info:

Target a script to specific page with Ka.Info.Page

Targetting specific pages with your JavaScript has never been easier. Just use the new JavaScript variable Ka.Info.PAGE. It contains a unique identifier for every KickApps page. For example, say you wanted to target some JavaScript for your "My Home" page. Simply follow these steps:

  1. Write your JavaScript code for that page as normal. (We'll wrap an if-statement around it later.)
  2. Surf to your "My Home" page
  3. If you're using Firefox and have the Firebug plugin installed, type this into your console window: Ka.Info.PAGE The response is the unique id string of that page.

    If you don't have Firefox or Firebug you can view the source code of the page and do a search for 'Ka.Info' and look for the value of PAGE. The id string for "My Home" for example, is 'pages/myPlace.jsp'. Copy this value and save it for the next step.
  4. Wrap an if-statement around the code you written in step one, checking if the Ka.Info.PAGE variable is the one you want: if (Ka.Info.PAGE == 'pages/myPlace.jsp'){ //my code for this page here. }

You can also target every page except for a certain page using the != operator, multiple pages using the && operator.

Target a script to a specific section of your site with Ka.Info.PAGETYPE

Using the Ka.Info.PAGETYPE variable, you can target your code for certain sections of your site (for example, all Message Board pages):

if (Ka.Info.PAGETYPE == 'mb'){ //my code for this section here. }

Just follow the same 4 steps in Ka.Info.PAGE replacing the PAGE reference with PAGETYPE. Note that not all KickApps powered pages have PAGETYPEs.

Detect whether a user is logged-in with Ka.Info.USERID

If the USERID variable is empty - it means no user logged-in. You can wrap your member-specific code around an if statement that checks for this:

if (Ka.Info.USERID != ''){ //enter code for logged in users }

Make it complex

Some pages have addition Ka.Info variables unique to that page. For example, all media play pages have an extra variable called Ka.Info.MEDIATYPE which tells you the format of the media ('AUDIO','VIDEO','BLOG'). Using a combination of these variables and the && (and), || (or), == (equals), != (not equas) operators you can really customize a script for almost any case.

Happy coding!

Did you enjoy this tutorial? Have questions, comments, or want to submit one of your own? Contact us at support@kickapps.com.