Opening jQuery Fancybox on page load

Posted Oct 27, 2010 | ~1 minute read

I recently came across a problem where i needed to open jQuery's brilliant FancyBox plugin on page load. Unfortunately, i couldn't see a route to do this through it's own API, so i delved into a way round this using just jQuery's awesomeness.

In most cases, the modal you want open will be opened by a link on your page. With that gem of knowledge, you can simply tell jQuery to action a link on the page.

Here's my code :

<script type="text/javascript">     
$(document).ready(function() {        
    $("#modal_link").fancybox().trigger('click');     
});
</script>

When the page is loaded, and ready to rock and roll jQuery in effect clicks the link and Boom! your modal window is open.

Hope that helped!