Jquery - 告诉哈希何时更改? [英] Jquery - tell when the hash changes?

查看:64
本文介绍了Jquery - 告诉哈希何时更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的网站正确回复后退按钮。我已经保存了我想要它做的哈希,但我不知道jQuery的钩子能够告诉哈希值何时发生变化。它不是.ready(),因为页面没有重新加载。我该怎么用?

I'm trying to make my site respond correctly to the back button. I've saved that hash of what I want it to do, but I don't know the hook for jQuery to be able to tell when the hash changes. It's not .ready(), because the page doesn't reload. What do I use?

编辑有点清晰:

I我正在使用iframe,所以当有人点击链接时我无法分辨。它位于相同的子域中,因此我能够看到它的文件路径,并保存它以便您可以添加书签。不幸的是,通过将其保存为哈希,我的后退按钮现在无法重新加载,无法重新加载iframe,因此我的后退按钮基本上已损坏。如果有办法告诉URI何时发生变化,我可以根据iframe地址进行检查,如果它们不匹配则更改它。

I'm using an iframe, so I can't tell when someone clicks a link. It's on the same subdomain, so i'm able to see it's filepath, and am saving it so you can bookmark. Unfortunately by saving it as a hash, my back button now fails to reload, which fails to reload the iframe, so my back button is essentially broken. If there was a way to tell when the URI changes, I could check it against the iframe address and change it if they don't match.

我只需要一个检查URI是否已更改的方法。是否有URI的.change()?沿着这些方向做什么?

All I need is a way to check if the URI has changed. Is there a .change() for the URI? Something along those lines?

推荐答案

文档准备好后,检查哈希并适当地改变页面。

After the document is ready, you examine the hash and alter the page appropriately.


我不知道jQuery的钩子能够告诉哈希值何时更改

I don't know the hook for jQuery to be able to tell when the hash changes

您可以截取哈希锚点击事件并进行适当响应,而不是等待哈希已更改事件(不存在)。

You can intercept your hash anchors' click events and respond appropriately as opposed to waiting for a "the hash has changed" event (which doesn't exist).

有些方法通过检查计时器上的 window.location.hash 来创建哈希已更改事件。

Some approaches create a "the hash has changed" event by inspecting window.location.hash on a timer.

这篇关于Jquery - 告诉哈希何时更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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