Sport Ngin User Group Forum
SportsEngineHQ Community Forum
Sign up Latest Topics

  Author   Comment  

Avatar / Picture

SportsEngine Moderator
Posts: 247
Occasionally, you'll want to open a page and show a tab on the tab element that isn't necessarily the first tab. There isn't a built in way to set the tab when a page loads, but with a little Javascript magic, you can accomplish this. It isn't pretty, but here you go!!

Take the code block below and insert it onto the page (I like sticking it on a tab in the tab element so it doesn't get 'lost.'

You can now use a query string in the URL to target a specific tab. For example, if I have a tab with three tabs called Red, Blue, and Yellow and I want to target the tab yellow I would input in the URL something like this

A couple of notes—if you have multiple tabs with the same name, it will set them all to the same tab. Set the Code Element title so you remember what this does!


function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(;
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

$j(window).load(function() {
var selectedTab = getParameterByName("tab");
if (selectedTab !== "") {
$j("ul.layoutContainerTabs span a:contains(" + selectedTab + ")").click();

A couple notes for anyone following along or using the script listed above:

  1. Be sure to clear the cache (both from your browser and the Sport Ngin page you just added this code to), otherwise it'll look like it doesn't work.
  2. The query string is case-sensitive. In this case, linking to will work just fine while will bonk. That is, unless you actually named your tab "yellow" (in lowercase).



Rob Bedeaux
SportsEngine, an NBC Sports Group company| 807 Broadway St NE, Ste 300, Minneapolis MN 55413

Junior Member
Posts: 13
This works pretty slick.  Thanks for sharing.
Previous Topic | Next Topic

Quick Navigation:

Easily create a Forum Website with Website Toolbox.

Powered by Website Toolbox - Create a Website Forum Hosting, Guestbook Hosting, or Website Chat Room for your website.