Note that there are some explanatory texts on larger screens.

plurals
  1. POChange URL with javascript
    primarykey
    data
    text
    <p><strong>I have a tab system in HTML that uses the following 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(); e.preventDefault(); }); })(); </code></pre> <p><strong>The HTML Markup is:</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> <p>The <em>UL</em> are the names of the tabs, when you click one they take you to the content of that tab. As you can see when you click a tab the link is www.thepage.com#tab1 etc but in the adress bar doesnt appear anything. I want to be able to go to thepage.com#tab2 and to show the tab 2, but this isnt working.</p> <p>I had searched different methods like <em>window.location</em> in javascript or <em>pushstate</em> in html5 posted in <a href="http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page" rel="nofollow">this page</a> but I didnt know how to make them function. It will be best to use thepage.com/tab1 and not the hash tag for SEO purposes. I know you can achieve this with the pushstate in html5 like:</p> <pre><code>window.history.pushState(“object or string”, “Title”, “/new-url”); </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.
 

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