I want to create a site which in the menu will contain links, probably <a> which will send some real hrefs, like /contact/ /services/ etc, so that when google bot visits the site, it will index it as real subpages.
But when the user clicks those links in browser, I don’t want the browser to refresh and reload content, I want the jQuery to shoot and change the content in the proper div, but should probably also change the url somehow, so that user can copy this link to his friends too.
I can do the jQuery content change part, I just don’t know how to create those links so that they don’t refresh the browser when javascript is active, but work properly when javascript is off (google bot).
Read about manipulating history
First two arguments are not necessary (at least I haven’t seen any useful usage), and I use it exactly like stated below
with javascript
However, the native browser’s back button is not supported. It means that when you hit back button, address changes to the old one but content stays the same. To workaround it, try to use following code
which will load old content as soon as user hits back button.
Also, you have to note that
.pushStatedoesn’t work on outdated browsers and therefore you should create a fallback for users without this feature.Eventually, as of jQuery 1.7, use .on() instead of .delegate(), because it’s faster and is being replaced. So instead of delegating whole body, we can use
which will attach event handler just to the specific elements.