-1

I'm having a strange issue which happens whenever a page is loaded with a hash at the end, ex. #home or #quotes. Some javascript breaks when there is a hash at the end of the link. The page works fine when there is no hash.

Live examples:

http://real-ufos.com/ - works

http:// real-ufos.com/#home - quite a few javascript things broken (earth's positioning, smooth scroll to hash section, comment tabs, opening prettyphoto lightbox etc)

Here is the scripts file: http:// real-ufos.com/wp-content/themes/real-ufos/js/scripts.js which I guess is most likely to contain the issue.

(Had to break up the links as I can't post more than one)

This is a similar question to Trailing hash (#) in URL breaks some Javascript? - but I couldn't find my answer there.

3
  • Have you looked for errors in your browser console? Uncaught Error: Syntax error, unrecognized expression: a[href=#home] Commented Jun 2, 2017 at 18:34
  • Try putting quotes around the href value: window.location.hash ? 'a[href="' + window.location.hash + '"]' at line 46 in your scripts.js?ver=4.7.5 so instead of a[href=#home] it comes out as a[href="#home"] Commented Jun 2, 2017 at 18:40
  • Woh! That did the trick. Thank you a ton. Commented Jun 2, 2017 at 18:47

1 Answer 1

0

When going to your page real-ufos.com/#home the browser console shows an error
Uncaught Error: Syntax error, unrecognized expression: a[href=#home]

A CSS or xpath selector of this form should have quotes around the value of the attribute: tag[attribute="value"]

You can change your scripts.js file to put in the quotes

window.location.hash ? 'a[href=' + window.location.hash + ']'
// becomes
window.location.hash ? 'a[href="' + window.location.hash + '"]'
//                             ^                            ^

This should make the syntax proper and correct the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.