Reputation: 1657
I am using jquery fancybox version 2.0.3. I want to prevent close on click outside of fancybox. I want to force user to click the cross button. I have tried
$(document).ready(function() {
$(".various").fancybox({
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
hideOnOverlayClick:false,
hideOnContentClick:false
}).trigger("click");
});
but this doesn't seems to work in new version of fancybox. I had referred the link
jquery fancybox - prevent close on click outside of fancybox
but these solutions doesn't seems to work in fancybox 2.0.3
Upvotes: 34
Views: 42438
Reputation: 63
$('.refer').fancybox({'width':395,'height':135,'type':'iframe',title:{type:'outside'},'closeBtn':false,helpers:{overlay:{closeClick:false}
}})
enter link description here
Upvotes: 0
Reputation: 567
The OP asked about fancyBox 2.0, but if you came here looking for an answer and are using fancyBox 3.0+, you can simply do:
$('.various').fancybox({
clickSlide: false, // disable close on outside click
touch: false // disable close on swipe
});
You can also completely disable the close button by adding smallBtn
and toolbar
to the options array and setting both to false
.
Tested with fancyBox 3.5.7.
Upvotes: 5
Reputation: 29
Using solution from Vennik - jsfiddle.net/5EV8r/425 .
If you want to prevent click outside.
Use it for example:
$(".fancybox_pdf").fancybox({
helpers : {
overlay : {closeClick: false}
},
autoSize: false,
afterShow: function() {
$(".fancybox-close").click(function(e) {
e.preventDefault();
last.click();
});
}
});
Upvotes: 0
Reputation: 1
$(document).ready(function() {
$("#popup").fancybox({
closeClick : false,
openEffect : 'none',
closeEffect : 'none',
helpers : {
overlay : {
closeClick: false,
}
}
}).trigger("click");
});
Upvotes: 0
Reputation: 41143
Use this option:
helpers : {
overlay : {closeClick: false}
}
so your final script should look like:
$(document).ready(function() {
$(".various").fancybox({
closeClick : false, // prevents closing when clicking INSIDE fancybox
openEffect : 'none',
closeEffect : 'none',
helpers : {
overlay : {closeClick: false} // prevents closing when clicking OUTSIDE fancybox
}
}).trigger("click");
});
hideOnOverlayClick
and hideOnContentClick
are options for Fancybox v1.3.x
Upvotes: 86