0

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 :)

1

3 Answers 3

4

When your button is clicked, add following line to your process function:

window.location = "#gallery"

It adds an anchor name to the browser's URL.

Then when the page is loaded, you should get this anchor name and show the right content:

var location = document.location.href;
var tabName = location.substring(location.indexOf('#') + 1);
showTab(tabName);
Sign up to request clarification or add additional context in comments.

1 Comment

+1 Exactly what I had as the answer too. It's probably the best way to do this.
1

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

Comments

0

You'd have to add parameters to your url query like www.yourdomain.com/index.html?openGallery=true or www.yourdomain.com/index.html#openGallery=true

Then using JS, on page load, have some code to check for those url parameters and launch your gallery.

1 Comment

An important OBS to this is IF he chooses to use the #openGallery=true he shall look for the hash value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.