2010-04-20 283 views
1

我已经构建了一个使用colorbox来显示图像的投资组合网页。我希望能够从发送给人的外部链接直接链接到该页面上的colorbox。如何从外部链接直接链接到彩盒?

有没有人有任何想法我可以如何实现这一目标?

回答

1

确保每个图像链接都有一个唯一的ID,例如, <一个ID =“照片1” HREF =“PHOTO1.JPG” >

添加像这样到您的文档准备功能,颜色框初始化代码后:

if (location.hash) { 
    var link = $(location.hash); // location.hash includes "#" in front 
    // change the hasClass() test below to match your image links only 
    if (link.length > 0 && link.hasClass('colorbox')) { 
     link.click(); // trigger colorbox 
    } 
} 

然后附加到ID发送链接该网址,例如http://example.com/#photo1

+0

这个(非常笨拙的)黑客工作,因为URL锚点哈希也是jQuery中的id选择器。 但是请注意,如果图像的id是它的文件名,那么你很可能不得不逃离它中的点,因为它是jQuery中的选择器:var link = $(location.hash.replace ( “ ”“ \\。”)); ''' – nojhan 2014-02-17 23:46:52