2012-02-05 131 views
1

如何在頁面上實現深度鏈接,以便當用戶從外部鏈接發出該頁面時,啓動fancybox模式。我是新來的JS/JqueryFancyBox/Popup深度鏈接

回答

0

我今天早上在找同樣的東西,發現你的問題以及有答案的論壇帖子。

(function() 
{ 
    var qs = location.search.slice(1), 
     params = qs.match(/&?ab=(\d+)\|(\d+)/); 

    if(params) 
    page(Number(params[ 1 ]), Number(params[ 2 ])); 

})(); 

「然後,如果你鏈接到該頁面通過你的兩個數值參數形式如下:?

concert.html AB = 1 | 5

它應該有調用頁面的驚豔效果(1,5);「當頁面加載

http://www.webdeveloper.com/forum/showthread.php?t=247899

希望它可以幫助 - 它幫助我。 :)

0

我剛剛用fancybox2和url哈希來解決它。

您可以使用Fancybox回調來設置和取消設置散列。
我在img標籤中使用數據屬性來存儲img標識符。
然後,您可以檢查頁面加載的URL中的散列值,獲取索引並使用給定索引打開fancybox。

var option = { 
     afterLoad: function(links) { 
      var title = links.element.attr('data-my-img'); 
      location.hash = title; 
     }, 
     afterClose: function() { 
      location.hash = ''; 
     } 
    }, 
    hash = location.hash.substr(1), 
    gallery = $('.fancybox'); 
    if(hash.length > 0){ 
     //id 
     var i = null; 
     gallery.each(function(index) { 
      var o = $(this).attr('data-my-img'); 
      if($(this).attr('data-my-img') == hash){ 
       i = index; 
       return; 
      } 
     }); 
     if(i != null){ 
      option.index = i; 
      $.fancybox.open(gallery, option); 
     } 
    } 
    gallery.fancybox(option); 
+0

只要參考這個鏈接http://jsfiddle.net/f2fRM/2/show。從url中刪除「顯示」以查看代碼 – 2013-01-23 13:18:31