Reputation: 543
Because of a new implementation of the cookie law, I have to gather consent for some cookies. One of the methods, is to wait for the user to scroll the page once, which has been legally meant to be an implicit consent.
I tried with:
jQuery(window).one('scroll', function(){
$(this).data('scrolled', true);
});
if(jQuery(window).data('scrolled')) {
console.log( 'ok' );
//place cookies
} else {
console.log( 'no' );
}
inside a script ( http://www.primebox.co.uk/projects/jquery-cookiebar/ ) that is called via:
$(document).ready(function(){
$.cookieBar({
});
});
However, console.log always tells me "no", regardless of the scrolling of the page.
Any hints? Thanks in advance
Upvotes: 0
Views: 206
Reputation: 1239
Check scroll and do some thing you want
window.onscroll = function (e) {
// called when the window is scrolled.
}
This will call every time when user scroll if you want to call it only once then do some trict
Make a hidden Field
Now set value of this hidden field to true when scroll method call
window.onscroll = function (e) { if (document.getElementById("ScrollOnceCheck").value == "false") { document.getElementById("ScrollOnceCheck").value = "true"; // update cookie } }
Upvotes: 1
Reputation: 36609
Your code works fine if I change this like this:
<script>
jQuery(window).one('scroll', function()
{
$(this).data('scrolled', true);
if(jQuery(window).data('scrolled'))
{
console.log('ok');
//place cookies
}
else
{
console.log('no');
}
});
</script>
However I could not make out what $.cookieBar is doing ?
Upvotes: 1