使用javascript从IE8地址栏中查找当前url

发布于 2024-09-28 20:48:57 字数 333 浏览 0 评论 0原文

当页面加载时,我更改了 url 中的书签。这样,当用户单击浏览器的后退按钮时,浏览器实际上不会返回,而是会更改书签。然后我可以检测书签更改并执行其他操作作为对用户按下后退按钮的反应。

我的问题是找到当前的网址,包括任何书签/哈希更改。它适用于所有浏览器,使用以下组合,但不适用于 IE8:

document.URL
location.href
window.location.hash

window.onhashchange

由于它不适用于 IE8,任何人都可以为我指出正确的方向我可以检测 IE8 中的书签/哈希更改吗?

I change the bookmark in the url when the page is loaded. That way, when the user clicks the back button of the browser, the browser will not actually go back, but will instead change the bookmark. I can then detect the bookmark change and do something else as a reaction to the user pressing the back button.

My problem is to find the current url, including any bookmark/hash changes. It works in all browsers, using a combination of the following, but not in IE8:

document.URL
location.href
window.location.hash

and the window.onhashchange

As it doesn't work for IE8, could anyone possibly point me in the right direction towards how I can detect the bookmark/hash change in IE8?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捂风挽笑 2024-10-05 20:48:57

看看 jquery-bbq,因为它实现了 hashchange 并使其在 IE6 中工作 -现在是 IE8,可能还有 IE9。您可能可以完全依赖它而不是您的自定义代码。

Look at jquery-bbq, as it implements the hashchange and makes it work in IE6-IE8 and possibly IE9 now. You could probably entirely rely on it instead of your custom code.

安静 2024-10-05 20:48:57

根据jQuery hashchange插件的作者介绍,IE8支持绑定到window.onhashchange 开箱即用的事件。

也许您可以尝试使用 Ben 的插件,该插件旨在在较旧的浏览器上启用哈希更改检测。

编辑:我的测试显示该事件在 IE8 中没有触发。然后我在上面插件的源代码中找到以下注释:

// Note that IE8 running in
// IE7 compatibility mode reports true for 'onhashchange' in window, even
// though the event isn't supported, so also test document.documentMode.

显然,我正在运行 documentMode 5 这是怪异模式。我敢打赌它只能在 IE8 标准模式下工作。无论如何,您应该能够实现相同的 JS Ben 使用的代码

According to the author of the jQuery hashchange plugin, IE8 supports binding to the window.onhashchange event out of the box.

Perhaps you could try using Ben's plugin, which is intended to enable hash change detection on older browsers.

EDIT: My tests showed that the event is not firing in IE8. Then I found the following comment in above plugin's source code:

// Note that IE8 running in
// IE7 compatibility mode reports true for 'onhashchange' in window, even
// though the event isn't supported, so also test document.documentMode.

Apparently, I'm running in documentMode 5 which is quirks mode. I bet it works in IE8 standards mode only. Regardless, you should be able to implement the same JS code that Ben used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文