views:

265

answers:

4

when you search on yelp, by adding additional search parameters the page does not reload. I think the results are changed based on ajax, however when you click on one of the restaruants and go back to the previous page. All of the parameters are still there. I noticed the address bars change as the parameters change. I found http://www.asual.com/jquery/address/ but it seems to add # at the end of the url. Is there a way to make it simply like index.php?xyz=1 without refreshing the page

A: 

It is impossible to change the URL (anything before a hash tag) with jquery for security reasons. If you look closely, they are actually using a hash tag:

http://www.yelp.com/search?find_desc=food&ns=1&find_loc=85022#find_desc=food

PHLAK
so how would i get the parameters values back?I cant simply do find_desc
hao
@hao: `window.location.hash` is your friend: https://developer.mozilla.org/En/DOM/Window.location#Properties Also have a look at http://ajaxpatterns.org/Unique_URLs
Marcel Korpel
A: 

yelp does the same: i reproduced the navigation you mentioned and here is the resulting url when going back to the search page:

http://www.yelp.com/search?find_desc=love&ns=1&find_loc=San+Francisco%2C+CA#places=CA%3ASan_Francisco%3A%3ACivic_Center%2FTenderloin

As you can see, there is a hash.

pixeline
A: 

The #(hash) key is the trick used by many people to build single web page apps(that do not reload).

The # comes from the bookmark on anchors <a href="#chapter1">Chapter 1</a>.
If you click that link, it will scroll to a text in the page that is just preceeded by a <a name="chapter1"></a>.

And when the user clicks on the Chapter 1 link, the url will become page.html#chapter1 and the page do not reload even if the text in the address bar has changed.

And that's the end of the fun part.

Now if you want to use the # key, you need either to build your own functions to handle it or use some libraries like the Really Simple History that will help you manage all the cross browser issues, when the user click back or next, etc...

Mic
The within-page links also work using id's of elements, so `<a href="#chapter1">Chapter 1</a>` will also point to `<h2 id="chapter1">Chapter 1</h2>` (and please watch your quotes: always use single or always use double quotes).
Marcel Korpel
@Marcel, Yeah, but id has some minor drawbacks when used with anchors, so I prefer to stick to the single "name" attribute logic. I've modified the quote to be correct. thanks.
Mic
@hao, you really need to accept this answer. Click on the check mark to increase your acceptance ratio.
Sebastián Grignoli
A: 

i'm not sure if i'm in the right place but what do these mean in the address bar: %2C %5F

Any idea?

OOF