只向用户显示一次警报 [英] Show an alert to a user only once

查看:62
本文介绍了只向用户显示一次警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在我网站的用户第一次访问时向他们显示弹出式提醒,但在后续访问时不显示.

I wish to show users of my website a pop-up alert on their first visit, but not on subsequent visits.

由于我只有基本的 HTML 和脚本知识,请解释我如何使用 cookie 或其他浏览器功能来实现这一点.

Since I only have basic HTML and scripting knowledge, please explain how I can i implement this using cookies or other browser features.

您可以在 http://www.hdfbcover.com/

推荐答案

这是一个使用 cookie 的示例,您也可以使用 localStorage 而不是 cookie 来做类似的事情.

Here is an example using cookies, you could also do something similar with localStorage rather than the cookie.

// Check If Cookie exists and if it doesn't exists
if( $.cookie('example') == null ) {
    // Create cookie
    $.cookie( 'example', '1',  { expires: 7, path: '/' } );
    // Display popup
    // Your code here...
}

参考:

这篇关于只向用户显示一次警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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