仅向用户显示一次警报(Show an alert to a user only once)
我希望在首次访问时向我的网站用户显示弹出提醒,但不会在后续访问时显示。
由于我只有基本的HTML和脚本知识,请解释我如何使用cookie或其他浏览器功能实现这一点。
您可以在http://www.hdfbcover.com/上查看我网站的当前状态。
I wish to show users of my website a pop-up alert on their first visit, but not on subsequent visits.
Since I only have basic HTML and scripting knowledge, please explain how I can i implement this using cookies or other browser features.
You can see the current state of my website at http://www.hdfbcover.com/
最满意答案
这是一个使用cookie的例子,你也可以用localStorage而不是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... }参考:
jQuery $ .cookie HTML5 localStorageHere 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... }Reference:
jQuery $.cookie HTML5 localStorage更多推荐
发布评论