哈希链接重新加载页面 [英] hash link reloads page

查看:165
本文介绍了哈希链接重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个安装在第三方网站上的代码片段。我无法深入细节,但它通过使用< script> 标记将HTML,CSS和JS加载到页面上。



部分代码是单击此链接时执行的JS函数:

 << ; a href =#>?< / a> 

如果页面上存在阻止执行该函数的JS错误,则单击该链接显然只会添加散列到URL并将用户带到页面的顶部。这是预期的回退行为。



然而,在一个第三方网站上存在大量JS错误,点击链接会删除顶级域名,添加哈希,并指向该页面(主页)。例如,该链接将从以下用户处获得:

  http://www.example.com/2010/05/14 / very-interesting-blog-post / 

  http://www.example.com/# 

值得注意的是,这个问题发生在Firefox和Chrome上,但不是IE9。我知道在没有更详细的代码的情况下正确诊断问题可能是不可能的,但我不能自由地提供它。我只是希望得到这种奇怪的浏览器行为的一些合理的解释。



如果它有帮助的话,那么这个网站就是一个WordPress博客。编辑:这显然不是由网站上的任何JS引起的,因为关闭JS并向检查员添加链接产生了相同的行为。

/ p>

解决方案

我有类似的错误,点击任何< a href =#> 导致整页重新加载。我设法通过从< head> 中删除​​< base href =/> >页面。我找不到任何关于这个(还)的信息。如果我能找到任何其他信息,我会添加更多。


I have a code snippet that is installed on third party websites. I can't get into the details, but it loads HTML, CSS and JS onto the page through the use of a <script> tag.

Part of the code is a JS function that executes when this link is clicked:

<a href="#">?</a>

If there are JS errors on the page that prevent the function from executing, clicking the link obviously just adds the hash to the URL and takes the user to the top of the page. This is the expected fallback behavior.

However, on one third party site with a multitude of JS errors, clicking the link removes everything after the top level domain, adds the hash, and directs to that page (the home page). For example, the link would take the user from:

http://www.example.com/2010/05/14/very-interesting-blog-post/

to

http://www.example.com/#

Notably, the issue occurs in Firefox and Chrome, but not IE9. I know it may be impossible to properly diagnose the issue without more detailed code, but I'm not at liberty to provide it. I'm just hoping to get some kind of reasonable explanation for this strange browser behavior.

If it helps at all, the site in question is a WordPress blog. Thanks in advance.

EDIT: This is apparently not caused by any JS on the site, because turning off JS and adding the link with the inspector produced the same behavior.

解决方案

I had a similar error where clicking on any <a href="#"> causes a full page reload. I managed to solve this by removing the <base href="/"> tag from the <head> of the page. I couldn't find any informations on this (yet). I'll add more if I can find any additional info.

这篇关于哈希链接重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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