0

Question: is there a way for a link to an anchor bookmark to arrive at its destination by loading another page first?

I'm developing a vertical-scrolling style website where the home page displays the contents of 3 other pages within sections or divs. Each section has a bookmark and a "back to top" link, and my main navigation menu uses custom bookmark anchor links. I'm also using thejQuery smooth scrolling plugin which works very well.

The problem I'd like to solve is that if you are not on the home page, but another page (such as the blog page) and you hit a bookmark link then the smooth scrolling effect can't work. It simply jumps straight there.

Would it be possible for the bookmark links to load the homepage first, and then continue to the required bookmark so the scrolling will still work??

1 Answer 1

0

I'm not entirely clear on what you're trying to do, but I assume that your 'bookmarks' are named anchors in the page itself? And that including those anchor names in hash tags in the URL causes the browser to jump directly to the named anchor on the page rather than starting at the top and smoothly scrolling down? I don't think you can stop this behavior. You can see an example of what I'm thinking you're doing here. Notice that if you load the page with #two in the URL the browser jumps to section two without scrolling.

You'll have to use hash locations that don't match anything on the page directly but can be processed by your script to find the correct location on the page and scroll to it after page load. That way the browser will do nothing because it can't find the anchor, but your script can. So in the above example you'd have a named anchor on the page named __two or something similar, then if you load http://server/#two your script reads location.hash and scrolls down after munging the anchor data.

1
  • Thanks Todd. Just saw your reply - Yes, that is exactly what I'm doing with the smooth scrolling plugin. The only problem is linking to a named bookmard from another page / location. My blog page is not contained on my main home page. So navigating from the blog page to, for example, the "about" section on the home page, it just jumps there. What I wondered was if there was a way to go to a named bookmark via the homepage url first. So clicking on "about" on the blog page would first go to home and then on to about, activating the scroll feature??????????! Jun 1, 2013 at 16:07

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.