离开网站时弹出 [英] Popup when leaving website

查看:107
本文介绍了离开网站时弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了JavaScript问题. 我想要一个脚本,该脚本将在退出整个网站时弹出一个带有问题的消息,如果访问者回答否",网页将关闭,如果访问者回答是",则将被重定向到另一个页面.我在 http://www.pgrs.net上找到了一个示例/2008/01/30/popup-when-leaving-website/,但似乎对我不起作用.我找不到任何解决方案. 请检查我的代码,并告诉我也许我做错了什么? 这是我的源代码.

I got a problem with JavaScript. I want a script that will pop-up on exit whole web-site a message with question and if visitor answers "NO" web page closes and if he answers "YES" he will be redirected to another page. I found a example at http://www.pgrs.net/2008/01/30/popup-when-leaving-website/ but it seems that it doesnt work for me. I couldnt find any solution. Pleae check my code and tell me maybe i'm doing something wrong ? Here`s my source code.

也许有人会遇到问题.

Maybe somebody will see a problem.

 <!DOCTYPE html>
<html lang="lt">
<head>
    <meta charset="utf-8">
    <title>PUA.LT</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="description" content="">
    <meta name="author" content="Perfect WEB Solutions">
    <link rel="stylesheet" href="<?php echo base_url("additional/style.css") ?>">
    <script src='<?php echo base_url("additional/prototype.js")?>' type='text/javascript' ></script>
</head>
<body>
<script type="text/javascript">


Event.observe(document.body, 'click', function(event) {
  if (Event.element(event).tagName == 'A') {
    staying_in_site = true;
  }
});

window.onunload = popup;

function popup() {
  if(staying_in_site) {
    return;
  }
  alert('I see you are leaving the site');
}
</script>

</body>
</html>

推荐答案

尝试一下:

window.onbeforeunload = popup;

function popup() {
  return 'I see you are leaving the site';
}

这篇关于离开网站时弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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