1

please can someone help me with changing the hash tag.

I am using the jquery .cycle script and my pages are sliding correctly to the next div which is fine, but at the moment, the address bar stays the same i.e. www.blahblah.com whether I am on the contact page or about us page, can someone please help me so that when I click contact us button, the address bar will change to www.blahblah.com/contact_us, I would like to do this for each page wit home being www.blahblah.com/index.html.

The second part to my question is how do I get the home button working so that it slides back the other way.

I'm very new to all this so if you could put a demo on jsfiddle or paste a working code, this will help me drastically. I only seem to earn by taking working code and chopping and changing it but for the life of me can't get this to work the way I want.

Here's the link to the jsfiddle demo.

Thanks for looking.

Barnee
  • 3,212
  • 8
  • 41
  • 53
Dan
  • 1,565
  • 3
  • 23
  • 43

2 Answers2

2

You can change the url hash using:

window.location.hash = 'whatever';

You can bind on hashchange an do whatever you want using (jQuery):

$(window).bind('hashchange', function() {   
   // Change the page here.... 
}); 

I personally mostly use the backbone framework for this kind of applications. Backbone has a thing called a 'router' which handles hash changes and such. Maybe you should check it out.

Also, check out this post.

Community
  • 1
  • 1
Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
  • Hi THanks for replying, i've taken a look at both comments but i'm really new to js and i don't understand enough yet, could you please please give me a demo of it working, i can then play about with it and understand it more. Thanks for what you've done. – Dan Mar 06 '12 at 12:54
  • Check out the links in my post. On the backbone page you can find some examples to get you going. – Bas Slagter Mar 06 '12 at 13:02
  • Hi Baszz, thanks for replying again but i've spent days looking at it and i can't get any further i hate to give up, so if you've got an idiots guide you can help me with i'll be stuck for months lol – Dan Mar 08 '12 at 14:06
1

You could probably extend the script using html5 pushstate.

The API is pretty easy. First argument is the state object, second the window title and third the url. For instance:

history.pushState(null, null, "/contact")

Maran
  • 2,751
  • 15
  • 12
  • Hi THanks for replying, i've taken a look at both comments but i'm really new to js and i don't understand enough yet, could you please please give me a demo of it working, i can then play about with it and understand it more. Thanks for what you've done. – Dan Mar 06 '12 at 12:54