Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anchor <a> tags not working in chrome when using #

Here is the code I am using on my page,

<li><a href="/explore/#Sound">Sound</a></li> 

(in a menu which appears on all pages)

<a id="Sound"><a> 

(on the page where i want to link to)

I have tried adding content to the tags with an id. But only in chrome the browser will not scroll down to the tag. These anchors work in IE&FF Any ideas?

like image 494
Jake_ Avatar asked Jul 26 '16 11:07

Jake_


People also ask

How do you use anchor tags?

The <a> tag (anchor tag) in HTML is used to create a hyperlink on the webpage. This hyperlink is used to link the webpage to other web pages or some section of the same web page.

What happens when you click an anchor tag?

The HTML <a> element (also called the anchor element), containing its href attribute, creates a hyperlink to other web pages, locations within the same page, location to a specified title of another web page, or to an email web page.


1 Answers

Turns out this was a bug in certain versions of chrome, posting workaround for anyone who needs it! :)

$(document).ready(function () {         var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);         if (window.location.hash && isChrome) {             setTimeout(function () {                 var hash = window.location.hash;                 window.location.hash = "";                 window.location.hash = hash;             }, 300);         }     }); 
like image 57
Jake_ Avatar answered Sep 24 '22 21:09

Jake_