离开网站时显示警告,而不仅仅是页面 [英] Display a warning when leaving the site, not just the page

查看:256
本文介绍了离开网站时显示警告,而不仅仅是页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来像是向我呈现的几乎不可能做的事情。我知道您可以在离开网页时显示一个对话框来确认。但是,离开网站时可以显示一个对话框吗?



我无法找到/创建任何可以阅读地址栏的内容,并且知道您正在离开网站。

解决方案

首先确定哪些事件可以让您的用户远离您的网站?


  1. 点击您网站内容的链接

  2. 向外界提交表单

  3. 来自小孩的JavaScript在其父项上更改window.location的窗口

  4. 用户在搜索栏中启动搜索(FF和IE)

  5. 输入搜索/地址的用户在浏览器地址栏中。

  6. 用户点击后退按钮(或退格键)刚刚到达您的网站

  7. 用户点击前进按钮或移位退格空间),当他们离开网站之前,通过返回按钮功能返回到该网站

  8. 用户关闭浏览器窗口

所以。你可以做些什么呢?


  1. 这些都很简单。检查您的锚点,如果它们指向外部,请在 onclick中添加一些功能事件

  2. 类似于1.添加您的功能 onsubmit 将表单发回到您的网站之外的事件。

  3. - > 8.没有真正有适用的解决方案被控制。您可以根据需要滥用 onbeforeunload 事件,但是您不会有太多的成功了解发生了什么。还有一些与 onbeforeunload 有关的限制,所以你的手大部分时间都会被束缚。



真正的问题?



为什么你想控制这个事件,除了打扰你的用户不要离开你。无论如何,乞讨在网络世界中没有多少正义。当一些网站会打扰我的消息,甚至更糟糕的是,阻止我离开我不想再回来了。它闻起来很糟糕的坏的可用性,并提供一些广告软件的网站。



相反,尝试通过向他们提供有价值的内容来保持用户的兴趣


This sounded like something almost impossible to do when it was presented to me. I know you can display a dialog box to confirm when leaving a web page. But is it possible to display a dialog box when leaving a site?

I haven't been able to find/create anything that can read the address bar and know that you're leaving the site.

解决方案

First off define which events can actually take your user away from your site?

  1. A click of a link inside your web site content
  2. A submit of a form to an outside action
  3. A javascript from a child window that changes window.location on its parent
  4. User starting a search in the search bar (FF and IE)
  5. User entering a search/address in the browser address bar.
  6. User hitting a back button (or backspace) when it just came to your site
  7. User hitting a forward button (or shift-backspace) when they were off the site before but came back by getting there via Back button functionality
  8. User closes the browser window

So. what can you do about all these?

  1. These are easy. Check your anchors and if they do point outside, add some functionality in the onclick event
  2. Similar to 1. Add your functionality for the onsubmit event of the form posting back outside of your site.
  3. -> 8. don't really have an applicable solution that could be controlled. You can abuse onbeforeunload event as much as you want, but you won't have much success of knowing what's going on. And there are certain limitations related to onbeforeunload as well, so your hands will be tied most of the time.

The real question?

Why would you want to control this event anyway except for bothering your users not to leave you. Begging doesn't give much justice in the web world anyway. And when some site would bother me with messages or even worse prevent me from leaving I wouldn't want to get back anymore. It smells of bad bad bad usability and gives a hint of adware site.

Rather try to keep your users interested by providing them with valuable content.

这篇关于离开网站时显示警告,而不仅仅是页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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