Show jQuery enabled notification message on download page

I went through the forums and read a lot of posts related to my question, but I could not find the answer I'm looking for.

I want to show a message with jquery to the user when the page loads and allow them to close the div by clicking on the close link. After closing, the script should remember that it should not be opened again during this session. I assume that he will use cookie.

Here is XHTML:

<div class="alertbox"> <span class="message">Please upgrade your browser</span> <div class="bloc_navigateurs"> <a href="http://download.mozilla.org/?product=firefox-3.6.13&amp;os=win&amp;lang=fr" target="_blank"><img src="includes/themes/default/images/icons/misc/Firefox-16.gif" width="16" height="16" alt="Firefox" /></a> <a href="http://www.google.com/chrome?hl=fr" target="_blank"><img src="includes/themes/default/images/icons/misc/Chrome-16.gif" width="16" height="16" alt="Chrome" /></a> <a href="http://www.01net.com/telecharger/windows/Internet/navigateur/fiches/13759.html" target="_blank"><img src="includes/themes/default/images/icons/misc/IE-16.gif" width="16" height="16" alt="Internet Explorer " /></a> </div> <span class="close">close</span> </div> 

As you can see, this advises the IE6 user to update the browser.

+4
source share
3 answers

I would use a jQuery cookie .

Bind a handler for the closeclick onclick event that creates the cookie. Before displaying a div, check your cookie.

 <script> $(function() { var $box = $(".alertbox"), stateCookieName = 'alertbox_state', alreadyClosed = $.cookie(stateCookieName); // The box should already be hidden initially (using CSS preferrably). // If not, uncomment the line below: // $box.hide(); // Show the box if it hasn't already been closed. if (alreadyClosed != 1) { $box.show(); } $box.find('.close').click(function() { $box.hide(); $.cookie(stateCookieName, 1); }); }); </script> 
+3
source

get cookie functions from here , then you can set alertBox to hide by default and:

 $(document).ready(function(){ if(readCookie('warnedIE')==null){ $('.alertbox').show(); createCookie('warnedIE','true',30); } }); 
0
source

Source: https://habr.com/ru/post/1332560/


All Articles