If I understand correctly:
- When a visitor clicks on an image, the image appears in the fancybox.
- When a visitor goes to the .html # image01 page, the page loads with the image already shown in fancybox.
- You want the url to be updated to page.html # image02 when the visitor clicks on image02.
In this case, you can set the url hash fragment when the image is clicked.
location.hash = "image02";
Using the attached example:
var thisHash = window.location.hash; $(document).ready(function() { $('.thumbs').fancybox({ prevEffect: 'fade', nextEffect: 'fade', closeBtn: true, arrows: true, nextClick: true, padding: 15, helpers: { thumbs: { width: 80, height: 80 } }, beforeShow: function() { var id = this.element.attr("id") if (id) { window.location.hash = id; } }, beforeClose: function() { window.location.hash = ""; } }); if (thisHash) { $(thisHash).trigger('click'); } });
source share