URL中的尾随井号(#)会破坏某些Javascript吗? [英] Trailing hash (#) in URL breaks some Javascript?

查看:70
本文介绍了URL中的尾随井号(#)会破坏某些Javascript吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我在尝试调试我们的Magento商店的问题时遇到了麻烦.其中一个模板文件中的某些嵌入式javascript没有运行,我不知道为什么.在查看其他产品的页面的另一个实例中,它运行得很好,但是在查看我遇到问题的产品时却不能.在某种程度上,在调试过程中,在URL的末尾添加了一个井号(#).由于某种原因,这导致Javascript无法运行.我删除了哈希,一切都按预期进行.我知道URL中的散列用于链接到锚点,您也可以使用我不熟悉但在寻找解决方案时遇到的散列来做其他花哨的事情.谁能解释这是怎么回事,以及为什么斜杠会破坏我的某些JavaScript?另外,您是否建议我采取步骤清理URL(可能使用htaccess规则),以使客户不会意外遇到此问题并骂我们网站损坏?

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?

谢谢!

推荐答案

您使用的js很可能会解析URL,并尝试将结尾部分(查询或其他内容)与特定字符串匹配.一旦添加#,该字符串将不再匹配,因此将不起作用.

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

这篇关于URL中的尾随井号(#)会破坏某些Javascript吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆