Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch jQuery Fancybox on page load?

I would like to launch a Fancybox (e.g. Fancybox's version of a modal or light box) on page load. I could bind it to a hidden anchor tag and fire the click event of that anchor tag via JavaScript, but I would rather just launch the Fancybox directly and avoid the extra anchor tag.

like image 267
Blegger Avatar asked Apr 30 '09 14:04

Blegger


People also ask

How do I open Fancybox on button click?

jQuery(document). ready(function($) { $('button'). on('click', function() { $. fancybox(); }); });

What is Fancybox jQuery?

fancyBox is a tool that offers a nice and elegant way to add zooming functionality for images, html content and multi-media on your webpages.

How do I close a fancybox after submitting?

You can close it with $. fancybox. close() .


1 Answers

Fancybox currently does not directly support a way to automatically launch. The work around I was able to get working is creating a hidden anchor tag and triggering it's click event. Make sure your call to trigger the click event is included after the jQuery and Fancybox JS files are included. The code I used is as follows:

This sample script is embedded directly in the HTML, but it could also be included in a JS file.

<script type="text/javascript">     $(document).ready(function() {         $("#hidden_link").fancybox().trigger('click');     }); </script> 
like image 65
Blegger Avatar answered Sep 17 '22 18:09

Blegger