检测用户点击链接,但中止 [英] Detect when user clicks link, but aborts

查看:96
本文介绍了检测用户点击链接,但中止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Web CMS。当用户点击链接移动到不同的页面或提交表单时,我想要一个请等待动画GIF显示在右上角,表示加载正在进行。

I am working on a Web CMS. When the user clicks on a link to move to a different page, or submits a form, I want a "please wait" animated GIF to show up in the top right corner to symbolize that loading is in progress.

但是,用户可以在浏览器中取消加载新页面,例如按取消按钮或ESC。在这种情况下,当浏览器停止加载下一页时,它们将保留在当前页面上。

However, the user can cancel loading of the new page in their browser, for example by pressing the "cancel" button or ESC. In that case, they will stay on the current page as the browser stops loading the next page.

如何在Javascript中检测到这一点,并隐藏等待图标再次?

How can I detect this in Javascript, and hide the "wait" icon again?


编辑:要解决你不应该这样做,浏览器已经有了注释。我有两个具体的原因来引入自定义解决方案。

To address the "you shouldn't do that, the browser already has it" comments. I have two specific reasons for introducing a custom solution.


  • 我在页面上有AJAX按钮。我需要一个活动指示符,所以用户不需要注意点击注册。

  • I have AJAX buttons on the page. I need an activity indicator for them so the user isn't confused whether the click registered or not.

在缓慢的连接有很多滞后,一些浏览器进度条会非常缓慢。我正处于一个现实生活的工作环境中,直到咳嗽者在IE6 / 7中显示出任何类型的活动。这给人的印象是,没有任何事情发生,应用程序反应非常缓慢,这让我很烦。我想要一个不断移动的指标(例如Safari的)。

On slow connections with a lot of lag, some browsers' progress bar will move extremely slowly. I am in a real-life work situation when it takes ages until the throbber shows any kind of activity in IE6/7. This gives the impression that nothing is happening and the app is reacting very slowly, and that annoys me. I want an indicator that is constantly moving (like Safari's, for example).


推荐答案

没有想到有办法做到这一点。我的意思是你可以发现一个逃生按键,这是值得的,但没有一般的方法来检测取消下一页加载。除了只是猜测,如果你提交/点击后还有几秒钟,那么它被取消或服务器的缓慢。或者在同一页面中使用AJAX进行整个导航和提交的内容,这样可以通过打破浏览器自己的停止按钮来避免问题;可能不是一个好主意。

Sorry, I don't think there's any way to do this, no. I mean you can spot an escape keypress for what that's worth, but there's no general way to detect a cancel of the next page loading. Other than just guessing that if you're still around a number of seconds after a submit/click then either it's been cancelled or your server's slow. Or doing the whole navigation and submission stuff with AJAX in the same page, which would avoid the problem simply by breaking the browser's own stop button; probably not a good idea.

(我不是一个很好的主意,添加一个自己的等待呃,无论如何,浏览器有一个完美的一个自己的!)

(I don't it's really a great idea to add a wait throbber of your own though anyway; the browser has a perfectly good one of its own!)

这篇关于检测用户点击链接,但中止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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