0

I have the same issue encountered by many others, but it seems there was no definitive answer, so I'm sorry if this counts as a double post.

My site http://brava-studio.com works with fancybox galleries. Originally, a user could only click a button to open a gallery. I also want to have specific urls that directs the user to a specific gallery. I made a temporary solution in which http://brava-studio.com/#EarthHouse directs to the 'Earth House' project gallery for example. Sadly, because of my bad code, everything that follows the # will direct to the same gallery.

my code below:

var thisHash = window.location.hash;
$(document).ready(function () {
    if (window.location.hash) {
        $("#fancybox-earth-g").trigger('click');
    }
});

combined from Fancybox blog => 6). Start FancyBox on page load :

jQuery(document).ready(function() {
    $("#your_selector").trigger('click');
});

and from How to create a direct link to any fancybox box

var thisHash = window.location.hash;
$(document).ready(function () {
    if (window.location.hash) {
        $(thisHash).fancybox({
            padding: 0
            // more API options
        }).trigger('click');
    }
    $('.fancylink').fancybox({
        padding: 0
        // more API options
    });
}); // ready
Community
  • 1
  • 1
Andrei M
  • 3
  • 3
  • Your link should point to the element's ID and not the `href` so in your case it should be [brava-studio.com/#fancybox-earth-g](http://brava-studio.com/#fancybox-earth-g)... then you can use `$(thisHash).trigger('click')`. – JFK Sep 12 '14 at 17:46
  • Thank you very much! :) It works! I was also trying to see if I can avoid the hash all together and have just http://brava-studio.com/fancybox-wave-g for example. – Andrei M Sep 12 '14 at 23:04
  • You could avoid the hash using rewrite rules inside your `.htaccess` file, but that's another story – JFK Sep 13 '14 at 00:01

0 Answers0