1

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

3 Answers 3

3

No need to use JavaScript:

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

You can still use JavaScript if you need it though:

location.hash = "tab3";
Sign up to request clarification or add additional context in comments.

1 Comment

Whoops, it was being added, but I was removing it after. All sorted now
1

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

Comments

1

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...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.