2

I ran into a real head scratcher recently while trying to debug an issue with our Magento store. Some of the in-line javascript in one of the template files wasn't running and I couldn't figure out why. It ran fine in another instance of the page viewing a different product but not when viewing the one I was having trouble with. Somehow, in the course of my debugging, a hash symbol (#) got added to the end of the URL. For some reason, this was causing the Javascript to not run. I removed the hash and everything works as expected. I know that hashes in URLs are used for linking to anchor points and you can do other fancy things with hashes as well that I'm not familiar with but ran across in my searching for a solution. Can anyone explain what's going on here and why a trailing slash breaks some of my javascript? Also, would you recommend I take steps to clean up the URL (perhaps with htaccess rules) so that a customer doesn't accidentally run into this problem and curse us for having a broken website?

Thanks!

1
  • The Fragment (The part behind the #) will never be sent to the server, so it won't be a server side issue. I am also not sure if that is really a client side problem, maybe it was just a coincidence that removing it also fixed the issue? Without having a look at your page and especially the affected URL this is really hard to say. Commented May 17, 2012 at 19:34

1 Answer 1

2

it is most likely the js you use parses the URL and try to match the end part (query or whatnot) to a specific string. once the # got added the string no longer matches and so it does not work.

of course, it could be other things but without seeing sample code that was my first thought

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

4 Comments

+1. A hash segment, in and of itself, would not break any existing JS code.
the problem I am describing is js parses url end part and try to match predefined string. something like trying to match the following, if(query == "cars") except query has a # at the end so it did not match therefore the js did not work because of no match. whatever was supposed to fire, didn't fire. from the author's description this seem like a possible problem
@Huangism, you're probably correct. So far as I know the code that wasn't working doesn't care about the URL, but perhaps something else does and the problem cascaded down and affected other code. As long as it isn't a known issue, I guess that answers it.
if you can post some sample codes, we can probably diagnose this further

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.