Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecific URL for each tab without reloading in javascript
    primarykey
    data
    text
    <p>I have a tab system and I want to be able to go to and url that opens a determined tab. Such as <em>www.site.com/tab2</em> (preferentially for SEO) or <em>www.site.com#tab2</em>.</p> <p>I've tried methods like <em>window.location</em> or <em>window.history.pushstate</em> (<a href="http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page" rel="nofollow">posted here</a>) but I didnt know how to make them function. <hr> <strong>Javascript:</strong></p> <pre><code>(function() { var $tabsNav = $('.tabs-nav'), $tabsNavLis = $tabsNav.children('li'), $tabContent = $('.tab-content'); $tabContent.hide(); $tabsNavLis.first().addClass('active').show(); $tabContent.first().show(); $tabsNavLis.on('click', function(e) { var $this = $(this); $tabsNavLis.removeClass('active'); $this.addClass('active'); $tabContent.hide(); $( $this.find('a').attr('href') ).fadeIn(); var hash = window.location.hash; var tab = parseInt(hash.replace('#',''), 10); $tabsNavLis.eq(tab - 1).click(); e.preventDefault(); }); })(); </code></pre> <p><hr> <strong>HTML:</strong></p> <pre><code>&lt;ul class="tabs-nav"&gt; &lt;li class="active"&gt; &lt;a href="#1"&gt;TAB 1&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#2"&gt;TAB 2&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="#3"&gt;TAB 3&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;&lt;!-- end .tabs-nav --&gt; &lt;div class="tabs-container"&gt; &lt;div class="tab-content" id="1"&gt; CONTENT OF TAB 1 &lt;/div&gt;&lt;!-- end #tab1 --&gt; &lt;div class="tab-content" id="2"&gt; CONTENT OF TAB 2 &lt;/div&gt;&lt;!-- end #tab2 --&gt; &lt;div class="tab-content" id="3"&gt; CONTENT OF TAB 3 &lt;/div&gt;&lt;!-- end #tab3 --&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload