dhtmlXTabBar Guide and Samples

Main features

  • Multibrowser/Multiplatform support
  • xHTML compatible
  • Full controll with JavaScript - wide API
  • Loading content with AJAX or in Iframes
  • Top, bottom, right and left oriented tabs
  • XML support
  • Fully customizable
  • Cool predefined skins
  • Multi-line tabbars
  • Scrollable
  • Easy initialization
  • Supported browsers

  • IE 5.5 and above
  • Mozilla 1.4 and above
  • FireFox 0.9 and above
  • Opera (Xml loading depends on browser version)
  • Safari 1.3 and above
  • Working with dhtmlXTabBar

    Initialize TabBar object from javascript constructor

    With Javascript constructor:
    <div id="a_tabbar" style="width:400;height:100"></div> <script> tabbar=new dhtmlXTabBar("a_tabbar"); tabbar.setImagePath("../codebase/imgs/"); </script> Parameters passed to the constructor are:
  • object to attach tabbar to (should be loaded before calling constructor)
  • Specify Additional parameters of the tabbar:
  • setImagePath(url) - method specifies the path to the folder with tree icons
  • Then you can load tabs from XML or add them with script

    Initialize TabBar object from HTML structure

    Without Javascript code:
    You do not need to write a line of javascript code if you include dhtmlxtabbar_start.js into the page. All you need is to specify class="dhtmlxTabBar" of the div element which is container for the tabbar, and tabbar object will be initialized inside automatically. <script src="../codebase/js/dhtmlxcommon.js"></script> <script src="../codebase/js/dhtmlxtabbar.js"></script> <script src="../codebase/js/dhtmlxtabbar_start.js"></script> <div id="a_tabbar" class="dhtmlxTabBar" imgpath="../codebase/imgs/" style="width:390; height:390;" skinColors="#FCFBFC,#F4F3EE" > <div id="a1" name="Tab 1">Content 1</div> <div id="a2" name="Tab 2">Content 2</div> <div id="a3" name="Tab 3">Content 3</div> </div>
    Container DIV attributes to use:
  • mode - tabbar orientation - top/bottom/left/right
  • tabheight - height of tab (not tab content)
  • imgpath - path to folder with tabbar images
  • margin - space between tabs
  • align - tabs align - right/left
  • hrefmode - see Loading contant in IFrames and Loading Content with AJAX
  • offset - offset of first tab from edge.
  • tabstyle - one of predefined styles: winDflt, winScarf, winBiScarf, winRound
  • select - id of selected tab
  • skinColors - list of two background colors - for active(1) and other tabs(2), like "#ffdead,#f5fffa"
  • style - you should specify width and height of tabbar area (with content)

  • Tab DIVs attributes to use:
  • id - identifier of tab
  • name - tab label
  • width - width of tab in pixels
  • href - url of tab content
  • row - row index
  • onbeforeinit - action called exactly before tabbar creation ( samples/tab_content_auto3.html )
  • oninit - action called exactly after tabbar creation ( samples/tab_content_auto3.html )


  • In this case the content of the tab should be placed inside tab DIV tags.

    Building tabbar with Javascript

    <div id="a_tabbar" style="width:400;height:100"></div> <script> tabbar=new dhtmlXTabBar("a_tabbar","top"); tabbar.setImagePath("../codebase/imgs/"); tabbar.addTab("a1","Tab 1-1","100px"); tabbar.addTab("a2","Tab 1-2","100px"); tabbar.addTab("a3","Tab 1-3","100px"); </script> Parametrs:
  • tab identifier
  • title/label
  • width
  • Building tabar from XML

    <div id="a_tabbar" style="width:400;height:100"></div> <script> tabbar=new dhtmlXTabBar("a_tabbar","top"); tabbar.setImagePath("../codebase/imgs/"); tabbar.loadXML("tabs.xml"); </script>

    XML Syntax: <?xml version="1.0"?> <tabbar> <row> <tab id="a1" width='200px'>Tab 1-1</tab> <tab id="a2" width='200px'>Tab 1-2</tab> </row> <row> <tab id="b1" width='150px'>Tab 2-1</tab> <tab id="b2" width='100px' selected="1">Tab 2-2</tab> <tab id="b3" width='150px'>Tab 2-3</tab> </row> </tabbar>
    In PHP script use the following code for page header:
    <?php if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) { header("Content-type: application/xhtml+xml"); } else { header("Content-type: text/xml"); } echo("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); ?>
    <tabbar> node is mandatory. It specifies the parent of loading block of data.
    Possible properties:
  • hrefmode - optional. Possible values are: ajax/ajax-html or iframe/iframe-on-demand. Defines the way of loading tab page content.
  • margin - space between tabs
  • align - align of tabs group - left/right
  • offset - offset of first tabs from edge
  • tabstyle - one of predefined styles: winDflt, winScarf, winBiScarf, winRound
  • skinColors


  • <row> can contain tabs (in order to load more than one level at once) or not.
    Mandatory parameters for this tag are:
  • width - width (height) of tab, * - mean automatic size detection
  • id - id of the node

  • Optional:
  • selected - to set tab active. This attribute should be set to single tab in tabbar.
  • href - url of the page to load under this tab (depending of tabbar/hrefmode it will use ajax or iframe)


  • Assigning content to tabs with Javscript

    With Javascript: <div id="a_tabbar" style="width:400;height:100"></div> <div id="html_1" >Some content</div> <script> tabbar=new dhtmlXTabBar("a_tabbar","top"); tabbar.setImagePath("../codebase/imgs/"); tabbar.addTab("a1","Tab 1-1","100px"); tabbar.addTab("a2","Tab 1-2","100px"); tabbar.setContent("a1","html_1"); tabbar.setContentHTML("a2","<br/>The content can be set as... </script>

    Assigning content to tabs in XML

    With XML <?xml version="1.0"?> <tabbar> <row> <tab id="a1" width='200px'>Tab 1-1 <content> <![CDATA[<img src='codebase/imgs/page_a.gif'>]]> </content> </tab> <tab id="a2" width='200px'>Tab 1-2 <content> <![CDATA[ <table> <tr><td>Some data</td></tr> </table> ]]> </content> </tab> </row> </tabbar>

    Loading content in IFrames

    If tabbar hrefmode set to "iframe" or "iframes-on-demand", tabbar will load content in iframes (which will be created automatically) <?xml version="1.0"?> <tabbar hrefmode="iframe"> <row> <tab id="b1" width='100px' href="http://groups.google.com">Google groups</tab> <tab id="b2" width='100px' selected="1" href="http://google.com">Google search</tab> </row> </tabbar> Possible hrefmode values are:
  • iframe - single iframe created and in content changed on active tab changing
  • iframes - iframes for each tab created and its content loaded at once
  • iframes-on-demand - iframes created only when tab activated
  • Loading Content with AJAX

    If tabbar hrefmode set to "ajax" or "ajax-html", tabbar will load content directly into the page (can contain javascript): <?xml version="1.0"?> <tabbar hrefmode="ajax"> <row> <tab id="b1" width='100px' selected="1" href="slow_ajax.php?num=1">SCBR 1</tab> <tab id="b2" width='100px' href="slow_ajax.php?num=2">SCBR 2</tab> <tab id="b3" width='100px' href="slow_ajax.php?num=3">SCBR 3</tab> </row> </tabbar> Possible hrefmode values are:
  • ajax - contnet loaded from xml (see structure below)
  • ajax-html - contnet loaded from html file ( any response will be threated as HTML and inserted inside tabbar )


  • In this case Tabbar expects AJAX request to get XML of the following structure: <?xml version="1.0"?> <content> <![CDATA[ Here should be the content that you want to place. It can be html code or simple text. ]]> </content>

    Mixed loading mode

    It is possible to mix any href based loading mode and static HTML tabs. Please check the sample of source code below. It creates an AJAX based tabbar, which has static first page. <script> tabbar=new dhtmlXTabBar("a_tabbar","top"); tabbar.setImagePath("../codebase/imgs/"); tabbar.setHrefMode("ajax-html"); tabbar.setSkinColors("#FCFBFC","#F4F3EE"); tabbar.addTab("a1","Static","100px"); tabbar.addTab("a2","AJAX","100px"); tabbar.setContentHTML("a1","Some static text here"); tabbar.setContentHref("a2","http://some.url/here"); tabbar.setTabActive("a1"); </script>

    Settings: position, align, offset, marging

    <div id="a_tabbar" style="width:400;height:100"></div> <script> tabbar=new dhtmlXTabBar("a_tabbar","top"); //top,bottom,left,right tabbar.setImagePath("../codebase/imgs/"); tabbar.setAlign("left"); //left,rigth,top,bottom tabbar.setMargin("2"); tabbar.setOffset("5"); tabbar.loadXML("tabs.xml"); </script>

    Skining: colors,predefined skins

    Predefined Style Schemas:
    There are 4 predefined schemas for Tabbar (see sample):
  • winDflt - Windows XP like (default style)
  • winScarf - same with one splay adge
  • winBiScarf - same with two splay adges
  • winRound - rounded tabs

  • To use necessary schema turn it on with setStyle method.

    TabBar colors:
    You can define background colors for tabs using setSkinColors method, where first argument sets background for active tab, second - for other tabs. <div id="a_tabbar" style="width:400;height:100"></div> <script> tabbar=new dhtmlXTabBar("b_tabbar","top"); tabbar.setImagePath("../codebase/imgs/"); tabbar.setStyle("winScarf"); tabbar.setSkinColors("#FFFF00","#FFFACD"); </script> Also you can define custom color for each tab separately by using setCustomStyle command tabbar.setCustomStyle('a4',"#F5F5DC","#F0F8FF"); This command assign the normal state and selected states of tab with ID==a4 ( please beware that command can be used BEFORE tab created, if tab already exists style will be applied only on tab state changing - selecting|deselecting, or after tabbar "normalization"
    This command also allows to assign custom css styles for text labels inside tabbar. <style> .black_white{ color:black; } .dhx_tab_element_inactive .black_white{ color:white; font-weight:bold; } </style> <script> tabbar2.setCustomStyle('a1','black','white',"black_white"); </script>

    Normalization

  • In each moment of time tabbar can be reconstructed - this means the same tabbar with the same content and caption will be rebuild from scratch automatically.
    It can be used for
    • adjusting tab caption sized to new tabbar size
    • automatically place tab captions on different rows to prevent scrolling
    • restoring correct layout after init in hidden container in Safari
  • //just rebuild tabbar, rows will be created automatically to prevent scrolling tabbar.normalize(); //same as previous, but the width of row will be limited to 600px tabbar.normalize(600); //same as previous, tab caption size on last row will be changed to fill all row tabbar.normalize(600,true);

    Manage tabbar and tab content area size

  • Set tabs content area size depending on content size
  • //param 1 - adjust width automatically //param 2 - adjust height automatically tabbar.enableAutoSize(true,true);
  • Set tabs content size depending on tabbar's container size (f.e. window size)
  • tabbar.enableAutoReSize(true);
  • Set fixed (minimal in case of AutoSize) size of tabbar
  • //param 1 - width //param 2 - height //param 3 - true means that givven size is size of contnet area only tabbar.setSize("200px","300px",true)

    Manage each tab with script API

  • Get/Set(change) label of tab
  • <script> //param - tab ID tabbar.getLabel(tabId); //param 1 - tab ID //param 2 - label string tabbar.setLabel(tabId,"New tab Label"); </script>
  • Show/Hide existing tab
  • <script> //param 1 - tab ID //param 2 - if true, then selection from hidden tab should be moved to nearest one tabbar.hideTab(tab,true); //param 1 - tab ID tabbar.showTab(tabId); </script>
  • Add/Remove tab
  • <script> //param 1 - tab ID //param 2 - new tab label //param 3 - size in px //param 4 - index in row (optional) //parma 5 - index of row (optional) tabbar.addTab(tabId,"Label",100,0,0); //param 1 - tab ID //param 2 - if true, then selection from deleted tab should be moved to nearest one tabbar.removeTab(tabId,true); </script>
  • Disable/Enable tab
  • <script> //param 1 - tab ID //param 2 - if true, then selection from disabled tab should be moved to nearest one tabbar.disableTab(tabId,true); //param 1 - tab ID tabbar.enableTab(tabId); </script>
  • Set/Get Active tab
  • <script> tabbar.getActiveTab(); //param 1 - tab ID tabbar.setTabActive(tabId); </script>
    © DHTMLX LTD.