Jonathan Clark
Jonathan Clark

Reputation: 20538

Manipulate URL segments with jQuery

I am developing a website where the user must be able to search a website by tags. I am using Codeigniter and I think I will be using jQuery for this somehow.

I need the URL to be:

http://example.com/keywords/firstkeyword+secondkeyword+thirdkeyword/

On the page I got a single search input field and when the user is "adding" a new keyword I need the URL to be updated when they hit enter but I do not want the page to be reloaded.

So if they add a forth keyword the URL should be:

http://example.com/keywords/firstkeyword+secondkeyword+thirdkeyword+forthkeyword/

I also need to be able to add other criterias after the keywords segment. For example size.

http://example.com/keywords/firstkeyword+secondkeyword+thirdkeyword/size/1+3+4/

How can I do this?

Upvotes: 0

Views: 444

Answers (2)

Mike
Mike

Reputation: 783

You might be looking for the HTML5 History API

Nice read, see #3 here

Upvotes: 0

Alessandro Vendruscolo
Alessandro Vendruscolo

Reputation: 14875

Changing the URL with Javascript will cause a redirect, unless you manipulate the part after the hash (#), which is accessible with window.location.hash.

Upvotes: 1

Related Questions