0

I am having issues implementing this solution for my iframe link: Fancybox3 with iFrame - prevent close on overlay click

Here is my example:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My page</title>

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.6/jquery.fancybox.min.css">
</head>
<body>

    <a data-fancybox data-type="iframe" href="https://fancyapps.com/" target="_blank" rel="noopener">Test Box</a>

<!-- JS -->
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.6/jquery.fancybox.min.js"></script>


<script type='text/javascript'>
$.fancybox({
    clickSlide: false
});

</script>

</body>
</html>

All libraries are current, but I can't get the javascript for the clickSlide to work. Thank you so much for any help.

2 Answers2

1

My best guess is that you aren't waiting for the DOM to load. I would say just put your fancybox initialization inside document.ready

$(document).ready(function() {
  $.fancybox({
     clickSlide: false
  });
})
Isaac Vidrine
  • 1,568
  • 1
  • 8
  • 20
0

You have syntax error, check documentation and use it like this -

$('[data-fancybox]').fancybox({
  clickSlide: false
});

https://codepen.io/anon/pen/LaYNbr?editors=1010

OR

$.fancybox.defaults.clickSlide = false;

https://codepen.io/anon/pen/KEKzaM?editors=1010

AND place your JS code before HTML or wrap inside $( document ).ready()

Janis
  • 8,593
  • 1
  • 21
  • 27