Display message when user leaves site

一世执手 提交于 2019-12-02 13:36:11

I will start by saying that I will not, in any way, recommend that you do this. It's a bad practice, it only annoys users and it makes you look extremely desperate. I repeat, don't do this, it's not a good idea, it's silly and it's not a good idea.

But the way you can do it is to only display the message when users are clicking on links that lead away from the site. You can do this by looking at the href attribute of the link and check if it's an external site. If it is, then display the message

But I repeat, don't do this!

We might be able to forgive you for window.onbeforeunload. But that's it!

There are some cases where this can be very useful and not having this feature will be annoying. One of the applications I developed for a client required users to input a lot of data on a page (close to 25 fields). I know it would have been better and more usable if the form was broken into more pages, but that's not the point here. There were instances where employees (mostly not very savvy computer users) entered data but for whatever reason left the page without submitting (accidentally, I am sure), resulting in frustration. I was happy to do window.onbeforeunload in that case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!