gpt4 book ai didi

javascript - 如何监听url的变化(Fragment identifier - the anchor part of a URL)

转载 作者:太空狗 更新时间:2023-10-29 13:20:57 28 4
gpt4 key购买 nike

我正在制作一个倾向于在一页 (Ajax) 中处理所有请求的网站。所以我想我可以捕获每个用户对链接的点击并检查IF它在我的网站上我在JavaScript上做一些事情,例如ajax请求,ELSE 它会像往常一样打开链接!

在 window.location 上监视没有用!而且我不知道是否有办法获取 # 符号后的 url 部分。注意:我猜 GMail 和 Facebook 都这样做!,他们使用这样的东西:
http://mail.google.com/mail/ #inbox
http://www.facebook.com/home.php #/inbox/?ref=mb

请考虑:我喜欢在我的项目中使用 jQuery,因此首选使用它的任何解决方案。

有什么想法吗?

最佳答案

这是另一篇不错的读物:Restoring Conventional Browser Navigation to AJAX Applications

文章摘录:

Many developers have adopted AJAX as a way to develop rich web applications that are almost as interactive and responsive as desktop applications. AJAX works by dividing the web UI into different segments. A user can perform an operation on one segment and then start working on other segments without waiting for the first operation to finish.

But AJAX has a major disadvantage; it breaks standard browser behavior, such as Back, Forward, and bookmarking support. Rather than forcing users to adapt to AJAX's shortcomings, developers should make their AJAX applications comply with the traditional web interaction style,.......

关于javascript - 如何监听url的变化(Fragment identifier - the anchor part of a URL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1657386/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com