0

I'm using this script and I want to save cookie when someone clicks inside iframe box, how can I do that, with this one, script repeats loading every time when user loads page, I would like to "hide" this for one day, and show i

<script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
<script type="text/javascript">
    var sec = 60;
    var timer = setInterval(function () {
        $("#wait").html('Ili sacekaj '+ eval(sec=sec -1) +' sekundi');
    }, 1000);
    setTimeout(function () {
        gasi();
        clearInterval(timer);
    }, 86400000000);

    window.onscroll = function () {
        if($.cookie('iframe')===undefined){
          //  window.scrollTo(500,500);
        }
    };
    $(window).on('blur',function(e) {
        if($(this).data('mouseIn') != 'yes')return;
        $('iframe').filter(function(){
            return $(this).data('mouseIn') == 'yes';
        }).trigger('iframeclick');
    });

    $(window).mouseenter(function(){
        $(this).data('mouseIn', 'yes');
    }).mouseleave(function(){
        $(this).data('mouseIn', 'yes');
    });
    $('iframe').mouseenter(function(){
        $(this).data('mouseIn', 'yes');
        $(window).data('mouseIn', 'yes');
    }).mouseleave(function(){
        $(this).data('mouseIn', null);
    });

    $('iframe').on('iframeclick', function(){
        console.log('Clicked inside iframe');
        $.cookie('iframe', '1', { expires: 1, path: '/' });
        location.reload();

    });
    $(window).on('click', function(){
        console.log('Clicked inside window');
    }).blur(function(){
        console.log('window blur');
    });

    function gasi()
    {
        $.cookie('iframe', '1', { expires: 1, path: '/' });
        location.reload();
    }
 
</script>
Cœur
  • 37,241
  • 25
  • 195
  • 267
MCalll
  • 1

1 Answers1

0

jQuery cookies is depracated, try to use this script instead : https://github.com/js-cookie/js-cookie

With this script you can try this:

<iframe src="http://stackoverflow.com/questions/1609741/how-to-add-click-event-to-a-iframe-with-jquery" class="yourclass"></iframe>


$("iframe.yourclass").click(function() {
  Cookies.set('insideIframe', '1', {
    expires: 7,
    path: ''
  });
})
Yuri Pereira
  • 1,945
  • 17
  • 24
  • I would like to do that with this script, because I'm not good at JS, I'm begginer and I got this script and I just need to make when someone clicks on iframe to hide that iframe for 1 day – MCalll Dec 21 '16 at 16:11