このコードは、各 Colorbox 画像に URL (domain.com/#image) を与えます。これをコピーして貼り付けると、その URL でサイトに入ると、必要な写真が自動的に開きます。
すべてが意図したとおりに機能しますが、URL の末尾に #image がない場合でも、サイトの最初の画像が自動的に開きます。URL に #image がある場合にのみ画像を自動的に開くようにするには、このコードをどのように変更すればよいですか?
ありがとう!
コード:
jQuery(function (){
var id, group;
group = jQuery("a[rel='lightbox[63]']").colorbox({onComplete:function(){
// Get the image URL
with_ext = (this.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1];
// Get the image url without the extension
without_ext = with_ext.substring(0, with_ext.lastIndexOf("."));
// Redirect
window.location.hash = without_ext;
}, onClosed: function(){
location.hash = '';
}});
id = location.hash.replace(/^\#/, '')+".jpg";
group.filter('[href$="'+id+'"]').eq(0).click();
});