Good day, please tell me how to implement this on jquery: do you need to make so that after every 5th user transition on internal links a modal window pops up?
2 answers
Write the number of transitions in the cookie to the user and when it is a multiple of 5, then open the modulochka. to work with cookies
<head> <script src="/path/to/jquery.cookie.js"></script> <script> var i = $.cookie('step') || 0; i++; $.cookie('step', i); if(i%5 == 0) { //ΠΎΡΠΊΡΡΡΠΈΠ΅ ΠΌΠΎΠ΄Π°Π»ΠΊΠΈ } </script> </head> This code should be on every page of the site.
- Thank you for the comprehensive answer - Sergeo Ayshev
|
Made as an example of clicks on links, but links should open in new windows.
If you want to save when navigating to other pages, you need to use localStorage
window.globalClick = parseInt(localStorage.getItem('globalClick')) || 0; $('a').on('click', function () { console.log('click', window.globalClick); if (window.globalClick == 5) { window.globalClick = 0; // ΠΊΠΎΠ΄ ΠΎΡΠΊΡΡΡΠΈΡ ΠΌΠΎΠ΄Π°Π»ΡΠ½ΠΎΠ³ΠΎ ΠΎΠΊΠ½Π° } window.globalClick++; localStorage.setItem('globalClick', window.globalClick); return false; }) UPD : added save to localStorage
- Thank you for your reply - Sergeo Ayshev
|