Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当用户第一次关闭特定页面时显示警报消息_Javascript_Jquery - Fatal编程技术网

Javascript 当用户第一次关闭特定页面时显示警报消息

Javascript 当用户第一次关闭特定页面时显示警报消息,javascript,jquery,Javascript,Jquery,我有一个jquery,它在页面第一次加载时显示警告消息,而不是再次加载,但现在我想要一个jquery,它在页面第一次关闭时显示警告消息,请任何人都能帮助我在give jquery中可以做些什么更改,这是页面加载 <script type="text/javascript"> // First Time Visit Processing // copyright 10th January 2006, Stephen Chapman // permission to use this

我有一个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>

//首次访问处理
//版权所有2006年1月10日,斯蒂芬·查普曼
//已授予在网页上使用此Javascript的权限
//前提是此脚本中的以下所有代码(包括
//注释)未经任何修改而使用
功能rC(不结盟运动)
{
var tC=document.cookie.split(“;”);
对于(变量i=tC.length-1;i>=0;i--)
{
var x=tC[i]。拆分('=');
如果(nam==x[0])
返回unescape(x[1]);
}
返回“~”;
} 
功能wC(nam、val)
{
document.cookie=nam+'='+escape(val);
} 
功能lC(nam,pg)
{
var-val=rC(nam);
如果(val.indexOf('~'+pg+'~')!=-1)
返回false;
val+=pg+'~';
wC(不结盟运动,瓦尔);
返回true;
} 
功能首次(cN)
{
返回信用证(“pWrD4jBo”,中国);
} 
函数thisPage()
{
var page=location.href.substring(location.href.lastIndexOf('\/')+1);
pos=页码索引('.');
如果(位置>-1)
{
第页=第页子项(0,位置);
} 
返回页面;
}
//调用它的示例代码-您可以根据需要修改它
函数start(){
如果(第一次(thisPage())){
//此代码仅在首次访问时运行
警惕(“欢迎”);
}
//每次加载页面时要运行的其他代码将转到此处
}
onload=启动;

这真的让事情过于复杂了吗

要在首次加载任何页面时提醒消息,请执行以下操作:

if ( ! localStorage.getItem(window.location) ) {
    localStorage.setItem(window.location, true);
    alert('Welcome');
}
在卸载之前,您不能在
上发出任何警报,但可以弹出确认对话框:

window.onbeforeunload = function(e) {
    if ( ! localStorage.getItem('unload_' + window.location) ) {
        localStorage.setItem('unload_' + window.location, true);
        return 'Dialog text here.';
    }
}    

可以使用中的localStorage shim添加对旧浏览器的支持。

这真的太复杂了吗

要在首次加载任何页面时提醒消息,请执行以下操作:

if ( ! localStorage.getItem(window.location) ) {
    localStorage.setItem(window.location, true);
    alert('Welcome');
}
在卸载之前,您不能在
上发出任何警报,但可以弹出确认对话框:

window.onbeforeunload = function(e) {
    if ( ! localStorage.getItem('unload_' + window.location) ) {
        localStorage.setItem('unload_' + window.location, true);
        return 'Dialog text here.';
    }
}    

可以使用中的localStorage shim添加对旧浏览器的支持。

谢谢您解决我的问题谢谢您解决我的问题