简体   繁体   English

永久关闭的jQuery弹出窗口

[英]Permanently Closeable jQuery pop-up

I have a moveable and closable jquery pop-up notification box. 我有一个可移动和可关闭的jQuery弹出通知框。 It works well aside from the fact that it pops up every time the page is loaded. 除了每次加载页面时都会弹出的事实之外,它的效果都很好。 What method would I need to implement to allow a user to permanently (or at least semi permanently) close the pop-up box? 我需要实现哪种方法以允许用户永久(或至少半永久)关闭弹出框?

If I need to use cookies how would I tie a cookie to a specific action like closing the div? 如果我需要使用cookie,我该如何将cookie绑定到诸如关闭div之类的特定操作?

yes you can use cookies. 是的,您可以使用Cookie。 when user click on the close button you can write it to the cookies. 当用户单击关闭按钮时,您可以将其写入cookie。 and when page load, if cookie is not available display the popup 当页面加载时,如果cookie不可用,则显示弹出窗口

You could simply use client side cookies: http://www.w3schools.com/js/js_cookies.asp 您可以简单地使用客户端cookie: http : //www.w3schools.com/js/js_cookies.asp

If the user doesn't have a cookie present, display box; 如果用户不存在Cookie,则显示框;否则,显示框。 If the user has the cookie present and cookie specifies the user has already closed the box, keep it closed; 如果用户有cookie,并且cookie指定用户已经关闭了该框,请保持关闭状态;否则,请关闭该框。 etc.. 等等..

It's simple, and doesn't put any extra weight on the server, you can also set a large expiry date if you want the popup not to show on theusers next visit for example. 这很简单,并且不会对服务器造成任何额外的负担,例如,如果您希望弹出窗口不显示在用户的下次访问中,则还可以设置较大的有效期。

Although this does depend on what it's for as sessions may also be another way of handling this. 尽管这确实取决于它的用途,但会话也可能是处理此问题的另一种方法。 (Sessions may mean that if the user comes back the next day for instance, the popup will show again depending on how it's set up) (会话可能意味着,例如,如果用户第二天回来,则弹出窗口将再次显示,具体取决于其设置方式)

session would be another candidate and its secure than cookies. 会话将是另一个候选者,它比cookie更安全。 And you don't have to do anything else than setting a variable on loading popup on first time and check afterwards if that variable is set or not. 而且,除了在第一次加载弹出窗口时设置变量,然后再检查此变量是否已设置之外,您无需执行其他任何操作。

Yes you can use cookies to do the trick, basically you're checking to see if the variable in the cookie is set, if not update the variable: 是的,您可以使用cookie来解决问题,基本上,您要检查cookie中的变量是否已设置,如果没有,请更新该变量:

http://www.w3schools.com/js/js_cookies.asp http://www.w3schools.com/js/js_cookies.asp

Don't forget that on close, you should update the cookie variable. 不要忘记,关闭时,您应该更新cookie变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM