当用户第一次关闭特定页面时显示警告消息
to show alert message when user closes particular page for first time
我有一个jquery,它在第一次加载页面时显示警报消息,而不是再次加载,但现在我想要一个jquery,它只在第一次关闭页面时显示警告消息。有人能帮助我在用于页面加载的give jquery中可以做什么更改吗?
<script type="text/javascript">
// First Time Visit Processing
// copyright 10th January 2006, Stephen Chapman
// permission to use this Javascript on your web page is granted
// provided that all of the below code in this script (including this
// comment) is used without any alteration
function rC(nam)
{
var tC = document.cookie.split('; ');
for (var i = tC.length - 1; i >= 0; i--)
{
var x = tC[i].split('=');
if (nam == x[0])
return unescape(x[1]);
}
return '~';
}
function wC(nam,val)
{
document.cookie = nam + '=' + escape(val);
}
function lC(nam,pg)
{
var val = rC(nam);
if (val.indexOf('~'+pg+'~') != -1)
return false;
val += pg + '~';
wC(nam,val);
return true;
}
function firstTime(cN)
{
return lC('pWrD4jBo',cN);
}
function thisPage()
{
var page = location.href.substring(location.href.lastIndexOf(''/')+1);
pos = page.indexOf('.');
if (pos > -1)
{
page = page.substr(0,pos);
}
return page;
}
// example code to call it - you may modify this as required
function start() {
if (firstTime(thisPage())) {
// this code only runs for first visit
alert('welcome');
}
// other code to run every time once page is loaded goes here
}
onload = start;
</script>
这真的太复杂了吗?
要在第一次加载任何页面时提醒消息,您可以执行以下操作:
if ( ! localStorage.getItem(window.location) ) {
localStorage.setItem(window.location, true);
alert('Welcome');
}
你不能在beforeunload
上真正提醒任何事情,但你可以弹出一个确认对话框:
window.onbeforeunload = function(e) {
if ( ! localStorage.getItem('unload_' + window.location) ) {
localStorage.setItem('unload_' + window.location, true);
return 'Dialog text here.';
}
}
可以使用MDN中的localStorage填充程序添加对旧浏览器的支持。
相关文章:
- Jquery单击按钮时不显示警告框
- 有一种方法可以使jslint在使用控制台时显示警告或错误
- 如何根据所选日期显示警告
- 在 中显示警告框 asp.net 将重定向到空白页,然后返回到原始页面
- 推送提交后,如果输入字段为黑色,则显示验证检查或以红色字母显示警告
- 带有合成和 Eslint 的 VIM:显示警告
- 功能点击不起作用...不显示警告框
- 无法使用 PHP 显示警告消息
- Plupload-在使用Flash Runtime且浏览器没有Flash时显示警告
- 如果在指定日期内,则使用日期选择器显示警告消息
- 删除行时,数据表显示警告
- 当用户第一次关闭特定页面时显示警告消息
- 如何在一半时间使用javascript完成在线考试时显示警告框
- Javascript函数不显示警告框
- 禁止在窗口上显示警告消息.打开
- 关闭弹出窗口时显示警告信息
- Javascript不显示警告消息
- ie浏览器显示警告值“未定义”;但火狐和chrome显示出了实际价值
- 如何使用Jquery保存数据后显示警告消息
- 如何将表单提交操作从显示警告弹出窗口更改为重定向到新页面?