0

So I know this might not necessarily be a "Drupal" issue, but because I am using Drupal and this issue only happens in my Drupal site, I'm wondering if it has something to do with the way Drupal handles URL's.

SO, I have an anchor on my home page like so:

<a id="we_know_digital" name="we_know_digital"></a>

There is a link in the main navigation that is on all pages to this anchor like so:

<a href="/#we_know_digital">We Know Digital</a>

So this works in all browsers, including Firefox, when I am ALREADY on the home page, however, if I am on one of the internal pages and then click this link, it takes me to the homepage, but does NOT go down to the anchor in Firefox. It does go down to the anchor in Chrome and Safari and other browsers, but for some reason it wont in Firefox, even in the latest version. The reason I believe this has something to do with the way Drupal handles URL's is that if I create a standalone plain vanilla HTML page outside of Drupal and replicate the same thing where I have 1 page that has the link and the anchor and then a separate page that has the link to the first page and the anchor, it works as expected in Firefox where it goes to the first page and then down to the anchor. It's only when I try to do this within Drupal, that it stops working. Anyone have any idea what might be going on here? I'm thinking it has something to do with the URL re-writing. ???

  • The fragment (bit after the #) doesn't get sent to the server, so it won't be a rewrite issue. If anything I'd say it's a Firefox bug/quirk. As a test: create 2 plain html files, one containing the source of your home page, one containing a link to it with the fragment at the end. Host them locally (local php server/node/whatever), and visit the page containing the link. When you click it, if Firefox doesn't take you to the right place, you'll at least know it's something between FF and your HTML, not Drupal/the server – Clive Jun 3 '16 at 20:05
  • By me in works in Firefox 46.0.1 including when not on the home page. And as Clive said: 6 Things You Should Know About Fragment URLs – J. Reynolds Jun 5 '16 at 6:50
  • So I tried saving off the HTML as static HTML pages and putting them somewhere on my server and creating a second static HTML page with nothing but the link to the anchor on the first page and I got the same exact behavior in Firefox. – Erich H. Jun 6 '16 at 17:45
0
<a id="we_know_digital" name="we_know_digital"></a>

The empty anchor target might be the problem. The browser may be having a "problem" fixating the empty (non-visual) target as the page loads.

Ideally, you would attach the id to something. eg. an Hn tag.

The name attribute on the anchor is deprecated in HTML5 if that is of concern. Reference: https://www.w3.org/TR/2008/WD-html5-diff-20080610/#absent-attributes

  • I changed my link in the main navigation to go to the ID of the actual div that exists right below the anchor, which is really where I want to go anyway, and I am getting the same exact behavior in Firefox. Works fine in all other browsers. – Erich H. Jun 6 '16 at 17:48
0

WOW, so sorry for the wild goose chase on this one. On a hunch, I decided to completely disable JavaScript in Firefox just to see what would happen and lo and behold, the problem went away and I started to get the behavior I expected. SO, I went into my custom.js JavaScript file that I had and went line by line to see if there was anything that looked obvious and I found this line:

$(this).scrollTop(1);

I have NO idea why I had that in there. I'm not sure if I was testing something at one point in time and just accidentally left it in there or if it was meant to do something important, but either way, I removed it, and now it works correctly in all browsers including Firefox. Thanks for all you're help on this one though. I learned more than I ever wanted to know about anchor links! :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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