views:

82

answers:

3

Is it possible to use javascript/jquery to append something on the end of a url when a link is clicked?

For example, I have 5 tabs on a page (product.php), when I click a tab, then that tab opens. What I want to do is have the URL change to product.php#tab-3 (or whichever number tab is clicked) when you click on it.

The reason I am doing this is so that users will be able to bookmark the page on a specific tab.

Thanks

+1  A: 

You can use the plugin jQuery Address http://www.asual.com/jquery/address/

camilleb
+1  A: 

No need to use JavaScript:

<a href="#tab3">click</a>

You can still use JavaScript if you need it though:

location.hash = "tab3";
Kobi
Whoops, it was being added, but I was removing it after. All sorted now
Probocop
A: 

maybe implement something like this

<div class="tabs" name="tab1">your tab handler 1</div>
<div class="tabs" name="tab2">your tab handler 2</div>
<div class="tabs" name="tab3">your tab handler 3</div>

And your code

$(".tabs").click(function()
{
     location.hash = $(this).attr("name");
});

Kind of easy way to automatic do what you want if you have keep changing tabs and order...