1.11M Members

Jquery UI tabs Hash Replace

 
0
 

I have the following script:

$(function () {
  var tabContainers = $('div.tabs > div');
  tabContainers.hide().filter(':first').show();

  $(window).bind('hashchange', function () {
    var hash = window.location.hash || '[b][b]#[/b][/b]first';

    tabContainers.hide();
    tabContainers.filter(hash).show();
    $('div.tabs ul.tabNavigation a').removeClass('selected');
    $('a[hash=' + hash + ']').addClass('selected');
  });

  $(window).trigger( "hashchange" );
});

    <div class="tabs">
        <ul class="tabNavigation">
            <a href="#first" class="selected">First</a>
            <a href="#second" class="">Second</a>
            <a href="#third" class="">Third</a>
        </ul>
        <div id="first" style="display: block;">
            <h2>First</h2>
        </div>
        <div id="second" style="display: none;">
            <h2>Second</h2>
        </div>
        <div id="third" style="display: none;">
            <h2>Third</h2>
        </div>
    </div>

How do i replace [b]#[/b] with [b]?[/b], so that it would be http://site.com/?first

 
0
 

So you want to change the meaning of the uri from #fragment to query ?key, having no value?

I believe that ? will initiate a page reload. The #fragment is like a bookmark, so it doesn't go anywhere, unless you have an accompanying name anchor on the page.

Why do you need to do this?

 
0
 

Just to make it look better.
Also, is there a way to disable hash jumping?

 
0
 

Just to make it look better.

That's what the ? character is for. The ? means 'start querystring from this point onwards'. You're happy for the page to refresh/reload when you press a link holding a href value with a '?' in it? If so, carry on.

ANyway, IMO, ? is an ugly character and many of us use mod rewriting to hide it! Well, OK, perhaps not the only reason to rewrite...

Also, is there a way to disable hash jumping?

WHat do you mean by that? Something like this?

http://stackoverflow.com/questions/3659072/jquery-disable-anchor-jump-when-loading-a-page

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: