我正在使用这个脚本,我想在有人点击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>
答案 0 :(得分:0)
jQuery cookies被删除,请尝试使用此脚本:https://github.com/js-cookie/js-cookie
使用此脚本,您可以尝试:
<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: ''
});
})