I’m making a gallery with jquery.
when i press a button on my page it fades out and the gallery should fade in. Can i change the url at the top so when a user copys the url and uses it somewhere else it opens up the gallery and not the first page (it’s actually all in one page i would only use the fade in and fade out functions to navigate trough different content)
i googled every possible word sentence and didn’t find anything so i would be relly thankful if someone could tell me the answer 🙂
I’m making a gallery with jquery. when i press a button on my page
Share
What youre looking for is commonly found in googles gmail. It uses anchors in URL (host/path?query#anchor) to detect previous location.
Because browsers do not send anchors to servers you cannot send the appropriate webpage back. This is done on the client, so you have to query an update from your server via ajax.
Anyway…
Step 1: Use anchors to navigate on your website ( a href=”#mypage1″ or updating the location property )
Step 2: When your index page loads check for anchors with
javascript (property window.location.hash
http://www.w3schools.com/jsref/obj_location.asp)
Step 3: Request an update from your server via ajax and parse it
when it arrives
I suggest you use json for content payloads. Easy to use, better than xml, much better than html (if you are tempted to use the innerhtml property). This is the most coplicated part.
Oh, you could just send the whole website and than just switch rather than loading via ajax, but I think people like the described way more.
Some links I found just now:
http://www.floatnotes.org/documentation/about-locations
http://blog.rebeccamurphey.com/2007/12/04/anchor-based-url-navigation-with-jquery