Jump to content

Recommended Posts

The website I'm currently working on requires for a tabbed menu one of the pages, much like the one on a user profile page of this site. I originally intended to use Bootstrap to make the tabs, but I also need support for users without Javascript. Is there any way to make the page so that users with JS enabled could browse the tabs without refreshing, while users with JS disabled could still view the content the old fashion way?

Link to comment
https://forums.phpfreaks.com/topic/279891-tabs-and-no-javascript-support/
Share on other sites

Yes, such a concept is known as Progressive Enhancement. Basically write the HTML in a way that works well without javascript, then use JS to modify it if necessary and add all the event handling. Eg, for tabs you'd maybe do something like:

<ul class="tab_menu">
  <li><a href="#tab1">Tab 1</a></li>
  <li><a href="#tab2">Tab 2</a></li>
  <li><a href="#tab2">Tab 3</a></li>
</ul>
<div id="tab1">
  <noscript><h1>Tab 1</h1></noscript>
  Tab 1 content
</div>
<div id="tab2">
  <noscript><h1>Tab 2</h1></noscript>
  Tab 2 content
</div>
<div id="tab3">
  <noscript><h1>Tab 3</h1></noscript>
  Tab 3 content
</div>
Without JS the user would just see a list of links at the top, and clicking the link would take them to the appropriate content section. If JS is enabled then the HTML/CSS gets modified to create the tab layout and let the user switch content sections by clicking the tab link.

 

Any well-written tab control script would allow for this type of setup. JqueryUI's and YUI's both work similarly to this. I'm not overly familiar with bootstrap but a quick glance at it's documentation seems to indicate it also follows a similar pattern as what I showed.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.