哈希链接重新加载页面

编程入门 行业动态 更新时间:2024-10-24 22:20:53
本文介绍了哈希链接重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

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

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

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

www.example/#

值得注意的是,这个问题发生在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:

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

to

www.example/#

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.

更多推荐

哈希链接重新加载页面

本文发布于:2023-11-01 19:59:09,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   页面   链接

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!