简体   繁体   English

JavaScript cookie保存

[英]JavaScript cookie save

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 我正在使用此脚本,当某人在iframe框内单击时,我想保存cookie,我该怎么做,对于此脚本,每次用户加载页面时脚本都会重复加载,我想“隐藏”这一天并显示给我

 <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> 

jQuery cookies is depracated, try to use this script instead : https://github.com/js-cookie/js-cookie jQuery cookie被弃用,尝试改用以下脚本: 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: ''
  });
})

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

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