如何通过javascript延迟离开页面? [英] How can I delay leaving a page via javascript?

查看:54
本文介绍了如何通过javascript延迟离开页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个人离开页面之前添加1000毫秒的延迟。我正在使用beforeunload事件来启动jquery动画,并希望它在页面离开之前完成。

I'm trying to get add a delay of 1000ms before a person leaved the page. I'm using the beforeunload event to start a jquery animation and would like it to finish before the page leaves.

我不关心旧版浏览器,IE9,最新版本safari,chrome和FF4都是我感兴趣的。

I'm not concerned with older browsers, IE9, latest safari, chrome and FF4 are all i'm interested in.

编辑:我希望在浏览内部网页时实现它。当然,我可以将所有内部链接作为javascript调用,但我更倾向于使用不那么强力的方法。

Well I was hoping to implement it when just navigating internal pages. Sure I can make all my internal links a javascript call, but I would have preferred a less brute force method.

此外,我不会阻止人们离开页面,甚至没有让他们等待很长时间,1秒钟的淡出?当我选择退出时,这并不比我播放的每一个游戏都要淡。

Also, I'm not stopping people from leaving the page, not even making them wait a huge long time, 1 second for a fade out? Thats no worse than every game I play fading out when I select quit.

现在我问过如何阻止一个人离开一个页面,然后是所有不要这样做本来应得的。

Now had I asked how do I prevent a person from leaving a page, then yes all the "don't do it" would have been deserved.

推荐答案

首先,如果人们想要离开你的页面,不要把离开它的任何障碍或困难。只是让他们。

Firstly, if people want to leave your page, don't put any barriers or difficulties in leaving it. Just let them.

Konerak 说得好......

Konerak said it well...


当用户即将离开页面而丢失数据时,可以使用阻止操作,但将其用于动画和噱头会很快惹恼你的用户。

Using a blocking action is acceptable when the user is about to lose data by leaving the page, but using them for animations and gimmicks will quickly annoy your users.

其次,你只能通过阻止动作阻止自动关闭,例如 alert() prompt(),临时阻止浏览器的视口,等待用户响应。

Secondly, you can only prevent automatic closing with a blocking action, such as an alert() or prompt(), which temporary blocks the browser's viewport, waiting for user response.

jsFiddle

这篇关于如何通过javascript延迟离开页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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